code blog

Use command line to backup/restore mysql databases

language: Bash/SSH

Use command line to backup/restore mysql databases

Unfortunately phpMyAdmin has limits when backing up or restoring databases. If you have a dedicated server, then the easiest way to get around phpMyAdmin is with SSH -- I use PuTTY.

backing up

mysqldump --opt -u[DB-USERNAME] -p[DB-USER-PASSWORD] DBNAME > backup.dump

restoring

mysql -u[DB-USERNAME] -p[DB-USER-PASSWORD] DBNAME < backup.dump

Note that in both cases the second "argument" after -p is the database name and not the password -- you'll be prompted for the password before the command executes.

the hostname....

In most cases the above lines work, but sometimes you also need to slip in a -h "argument"

mysql -h HOSTNAME -u[DB-USERNAME] -p[DB-USER-PASSWORD] DBNAME < backup.dump

I had to do that when working on Media Temple.

Comments

Restore database

Command line is the best and easiest way to take backup of mysql database.

web design Florida

User login