MySQL Tutorial – Import or Export A DatabaseThis tutorial outlines the steps for importing and exporting MySQL databases via command line (SSH). Click Here for information about getting SSH access.
1. Export A MySQL Database
This example shows you how to export a database. It is a good idea to export your data often as a backup.
- Using SSH, execute the following command:
mysqldump -u username -p database_name > dbname.sql- You will be prompted for a password, type in the password for the username and press Enter. Replace username, password and database_name with your MySQL username, password and database name.
File dbname.sql now holds a backup of your database and is ready for download to your computer.
2. Import A MySQL Database
The file must be in .sql format. It can not be compressed in a .zip or .tar.gz file.
- Start by uploading the .sql file onto the Bluehost server
- If you haven’t already done so, create the MySQL database via the cpanel. Click Here for further instructions
- Using SSH, navigate to the directory where your .sql file is.
- Next run this command:
mysql -p -u username database_name < file.sqlNote: The -p will prompt for your account’s password.
Note: username is the user with rights to the database. If you are unsure what the username is you can use the same username and password used to sign into SSH.
Note: Make sure your database name has your Bluehost username prefix with the _ (underscore) after it and the database name.
How do I create an empty MySQL Database
Solution:
To create the database, do the following:
- Log into the cpanel
- Click the MySQL Databases icon under the “Databases” category
- Create a New Database (make it short best result)
- Add New User (make it short best result)
- Most importantly, select the user and database underneath “Add User To Database” and click “Add” (authentication will not work if you do not click this button).
After doing all these steps, you can create the database tables either via phpMyAdmin or use an online PHP or Perl script.The username format will be: username_dbusername
The database format will be: username_dbname
The hostaddress will be: localhostFor example, if you enter the following variables:
dbusername: admin
dbname: DB1
password: passwordYou will end up with the following format that you would place in your connection string
Hostname: localhost
dataName: username_db01
dataUser: username_admin
Password: passwordNotice the password remains the same format.The connection string can be either of any examples below:
For example, we will use the above example variables:
Connection Strings
For PERL
$dbh = DBI->connect(“DBI:mysql:username_db01:localhost”,”username_admin”,”password”);For PHP:
$dbh=mysql_connect (“localhost”, “username_admin”, “password”) or die (‘I cannot connect to the database.’);
mysql_select_db (“username_db01″);To create tables and other functions, you can use the PHPMyAdmin located in the Databases section of the cPanel. For more information on how to work with PHPMyAdmin. please visit: phpmyadmin.net.
Keywords: MySQL Database CreationSOURCE : BLUEHOST
Popularity: unranked [?]
