How can we import a database?
There are multiple ways by which you can import the contents of a MySQL database, two methods that can be done directly with the tools on our servers:
Importing Databases via phpMyAdmin
Importing Databases via Command Line (SSH)
This article also features a list of common issues and recommended solutions:
Common Issues
Importing Databases via phpMyAdmin
- Go to >> phpMyAdmin
- Click the new database name in the top left
- Click Import in the main area of phpMyAdmin
- Browse for the .sql file on your computer and click Go
The optional step depends on if the new database name exists. If yes, then go ahead and click it. If no, skip it. If you get an error, refer top the list below.
Importing Databases via Command Line (SSH)
To import your database after you have to login to your account with SSH:
1. Upload your database to your home directory (This may be done with cPanel File Manager, an FTP client, or SSH).
2. If the database does not exist, please create a database, a user, and give the user full privileges to the database. Note the username and password.
3. Log into your server via SSH.
4. Use the ls -l command to verify that the file is in your current directory.
5. If the file is not present, upload/move the file to the correct directory, or navigate to the directory where the file is located.
6. Enter the following command, replacing ‘user_name’, ‘database_name, and ‘file.sql’ with the correct values for your database and file : mysql -p -u user_name database_name < file.sql
7. You will be prompted for your database user password, and then your database will be imported.
Common Issues
Your import file is too large!
The phpMyAdmin upload limit on buzinessware shared and reseller hosting packages is 50mb. This is also the default on VPS and Dedicated servers.
#1044 – Access denied for user ‘username1’@’localhost’ to database ‘user2_wrdp9’
The problem here is your import file contains an SQL query that attempts to create a database for the wrong username. Notice the user2 in ‘user2_wrdp9’ does not match the username1 in ‘username1’@’localhost’. Someone must edit the import file and change the old user2 to your new username1. (If you do not feel comfortable editing your import file, we will be glad to help you do that.) Here is an example of what it looks like (notice 3 places where the username is outdated):
□□--□-- Database: `user2_wrdp9`□--□CREATE DATABASE `user2_wrdp9` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;□USE `user2_wrdp9`;□□--
#1049 – Unknown database ‘username1_wrdp9’
The problem is your import file does not have a query to create the database before importing the
data. Simply go to cPanel > MySQL Databases and create a database with that name (in my example, “wrdp9”). Then re-attempt your import.
#1007 – Can’t create database ‘username1_wrdp9’; database exists
The problem here is your import file contains an SQL query that attempts to create a database that already exists. If the database is empty, simply go to cPanel > MySQL Databases and remove that empty database; then re-attempt your import. If the database is not empty, someone must edit the import file and remove the CREATE DATABASE query. (If you do not feel comfortable editing your import file, we will be glad to help you do that.) Here is an example of what it looks like:
□CREATE DATABASE `username1_wrdp9` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near…
The file does not contain backup data for a database, or the file has been changed or corrupted.
Less Common Issues
ERROR 1044 (42000): Access denied for user ‘username1’@’localhost’ to database ‘username1_wrdp9’
If you get this error, you do not have privileges on user_* to use Create. Buzinessware needs to correct this issue for you.
However, if you need to import now, and can’t wait, here is a work-around.
The problem here is your import file contains at least one SQL query that attempts to create a database, and you do not have the privilege to do so. Someone must edit the import file and remove the CREATE DATABASE query. (If you do not feel comfortable editing your import file, we will be glad to help you do that.) Here is an example of what it looks like:
□CREATE DATABASE `username1_wrdp9` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
After you remove this code, you must go to cPanel and click the MySQL Databases icon. Here you must create your database with the name which was removed from the import file (in my example, “wrdp9”). Then you can Import the modified import file and it will work.