Saturday, January 29, 2011

mySQL Database Backup and Import

For mySQL database backups use following commands:

c:\>mysqldump -u [USER] -p -P [PORT] --all-databases > [FILE]

For example, the command will look like this:

c:\>mysqldump -u root -p -P 3306 --all-databases > mydump.sql

After you press enter you will be asked for password and then your backup file will be created.

You can also choose to export/backup only select databases.


For restoring the backup:

mysql -u root -p -P 3306 < mydump.sql

Note that in this case while restoring the databases all the existing databases / tables with the same names will be dropped and recreated with the data in the dump file.

Note: If your mySQL bin directory is not specified in the PATH variable you will need to go to the directory where mySQL is installed and then fire this command


- Siddhesh Prabhu

Team Lead - J2EE Application Development
NAVSYA Technologies Pvt. Ltd.
http://www.navsya.com

No comments:

Post a Comment