2

I created a database on the host server using PHPMyAdmin.

I exported the database for local development and have since added data and changed the schema slightly.

How can I replace the database on the server with my local version? Some source I read say to go to that database in PHPMyAdmin and upload, but I'm not convinced that is correct.

How do I replace a MySQL Database?

3 Answers 3

1

Yes you can. You just export your database as sql file and import it via phpmyadmin.

Export:

Export database via phpmyadmin

Import:

Note that if you have a very large sql file your host might not let you upload it via this wizard.

Import database via phpmyadmin

2
  • 1
    Note that this method fails, because the Export script is trying to create tables that already exist. You'll need to drop those tables from the server database first.
    – mmcglynn
    Dec 16, 2015 at 13:04
  • However, if you pick "Custom" as the Export Method then you get the options to "Add DROP DATABASE statement", "Add CREATE DATABASE", "Add DROP TABLE", "CREATE TABLE IF NOT EXISTS", etc.
    – MrWhite
    Dec 16, 2015 at 23:28
1

There is an alternative way to export and import the database if you have terminal access to the server.

Export the file via terminal Execute the following command replacing the MySQL username, database name, and the filename you wish to create.

mysqldump -u <username> -p <dbname> > <filename>.sql

Import the file using terminal After uploading the file to your server, you can browse to the location and execute the following command replacing the MySQL username, database name, and the filename you already have.

mysql -u <username> -p <dbname> < <filename>.sql
0

On your local machine you need to backup the database in .sql format. Once you do, access phpMyadmin from your cPanel. Click on the database and import the .sql file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.