Export / Import MySQL database

I have a MySQL database on a web server with about 30 tables. I need to export it and import it into another database. The new database has a different name than the old database.

I exported the database to my local machine using phpmyadmin, selecting ALL tables.

See attached as the first part of the exported SQL file.

Can I just import that file into the other (empty, no tables) database & change Database: `db203755816` in the first line to the new database name?

Richard KortsAsked:
Who is Participating?
ramromConnect With a Mentor consultant Commented:
You should be able to do that. There is no need to change Database: `db203755816', as that is just a comment.
Is it a linux machine that is running MySQL?  If so you can EASILY export/import like so:

Export the database:

mysqldump -u root -p *dbname* > outputfile.sql

Of course replace *dbname* with the name of the database and you can call the output file whatever you like.

Import the database:
Copy the output.sql file to other server and run command:

mysql  -u root -p *dbname* < outputfile.sql

Same as above, use the new database name that you want to import to.
Marco GasiFreelancerCommented:
You can simply use PhpMyAdmin to import the whole database: i did it svereal times.

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Mohamed AbowardaSoftware EngineerCommented:
There are many way you can use, you can use PhpMyAdmin, or you can use a custom PHP script, you might also be able to use cPanel if you have cPanel installed.

To use a custom PHP script:

To use PhpMyAdmin:
Julian HansenCommented:
Just a note - the script you posted is incomplete and will fail on the last line. It looks like the file was truncated.

The only things to watch out for (assuming a complete script) are

a) Use database statements - remove if moving to another DB
b) Views and stored procedures need to be exported and imported correctly

Also there is no drop table statements in the script so if the tables already exist this will generate an error but the data should still be imported.
Richard KortsAuthor Commented:
Worked like a charm.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.