How to import, export, copy, rename, merge MySQL database
Finding phpMyAdmin in your Control Panel
One you have created a database, you can access it via the web administration panel.
cPanel
- Login to cPanel.
- There will be an icon for phpMyAdmin in the Databases section. This will take you to phpMyAdmin.
- The list of available databases will be listed on the left hand side once you get into phpMyAdmin.
How can I import a database?
- Go to phpMyAdmin
- Click the new database name in the top left (optional)
- 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.
Instructions on Exporting a Database
- Go to an existing database in phpMyAdmin.
- Click Export at the top.
- Leave the settings as they are, click the “Save as file” checkbox and click Go.
- This will download a .sql file to your computer.
How to copy a database in phpMyAdmin
- Select the database you wish to copy (by clicking on the database from the phpMyAdmin home screen).
- Once inside the database, select the Operations tab.
- Scroll down to the section where it says “Copy database to:“
- Type in the name of the new database.
- Select “structure and data” to copy everything. Alternately, you can select “Structure only” if you want the columns but not the data.
- Check the box “CREATE DATABASE before copying” to create a new database.
- Check the box “Add AUTO_INCREMENT value.”
- Click on the Go button to proceed.
How to rename a database in phpMyAdmin
The latest version of phpMyAdmin allows you to change the name of the database.
Keep in mind that when you change the name of a database, you will have to reconfigure user permissions and any scripts that you want to continue referencing this database.
Before You Begin
For cPanel: If you want the same database user to have access to the renamed database, you should take note of the username already assigned to the database, which may or may not be similar to the name of the current database.
- In cPanel, click on MySQL Databases.
- Scroll down to the Current Databases section of the page.
- Find the database you are about to rename, and take note or remember the database user already assigned to the database. You will need to know this for step 2.
- You can return to the cPanel home screen to begin Step 1.
Step 1: Renaming the Database
- From cPanel, click on phpMyAdmin. (It should open in a new tab.)
- Click on the database you wish to rename in the left hand column.
- Click on the Operations tab.
- Where it says “Rename database to:” enter the new database name.
- Click the Go button.
- When it asks you to want to create the new database and drop the old database, click OK to proceed. (This is a good time to make sure you spelled the new name correctly.)
- Once the operation is complete, click OK when asked if you want to reload the database.
Step 2: Reconfiguring User Permissions
If your hosting plan has cPanel, then you will need to reconfigure user permissions.
- Go back to the main cPanel page.
- Click on MySQL Databases.
- Scroll down to the Add User To Database section of the page.
- Select the database from the list (should be the new name).
- Select the database user from the list (the same one that used to be associated with this database).
- Click on Add button.
- On the Manage User Privileges page that appears, check the box next to All Privileges.
- Click on the Make Changes button.
Step 3: Update Scripts
You may need to update any scripts or applications that reference this database, since the name has changed, if you want them to continue to have access to this database.
Merge two MySQL databases
The easiest way I can explain this is show you how to copy data from a table to another table.
Both databases need to exist on the same account. If they do not, you will need to create a backup of one and move it. (If both databases have the same name, you will need to also rename one before moving).
Once both are on the same account, login to either SSH or cPanel.
cPanel
- From cPanel, you need to click the phpMyAdmin icon.
- Click the SQL tab at the top. You will see where it says, ‘Run SQL query/queries on server “localhost”:’
- In the text box below that, insert the following code, but replace DB1 and DB2 with the database names. Also, replace TABLE1 with the table name you are trying to merge.
INSERT INTO DB1.TABLE1 SELECT * FROM DB2.TABLE1
- Click the Go button.
- Repeat for any other tables you want to merge.
Shell (SSH)
- From SSH, you need to type the command to access mysql. Here is the format, but replace MYNAME with your username and PASS with your password.
-
mysql -u MYNAME -pPASS
- Now type the following code, but replace DB1 and DB2 with the database names. Also, replace TABLE1 with the table name you are trying to merge.
INSERT INTO DB1.TABLE1 SELECT * FROM DB2.TABLE1;
- Hit the Enter key.
- Repeat for any other tables you want to merge.