MySQL Command line database copy

      No Comments on MySQL Command line database copy

Sometimes you need to copy a database to a dev database or something. You can usually do this through phpmyadmin, but it’s so much faster, especially with large databases, to do it through command line.

Once ssh’d into a server with mysql on it, create a new database for the one you’re going to import data into, this can be done in phpmyadmin, or through command line. This is how I would do it in command line:
[code]
mysql -u user -ppassword
mysql> create database new_database;
exit
[/code]

Then type these two commands to the ssh terminal
[code]
mysqldump -u USER -pPASSWORD old_database > filename.sql
mysql -u USER -pPASSWORD new_database < filename.sql
[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *