Dumping / backup and restore mySQL server’s database from command console

Of course dumping and restore mysql database can be done easily with phpmyadmin. But what if phpmyadmin is in error state and you need to backup your database on server A  immedietly and move it to server B?

The answer is use command console, if you backup database od your virtual private server or dedicated server, login first as root from SSH access

Lets say you want to backup a mySQL database named “wp_1″ and your mySQL’spassword is “246passwd” your home directory is “rootzone”

1. Dump / backup mySQL database

After you’re in console as root, enter this command :

# mysqldump -uroot -p246passwd wp_1 > /home/rootzone/wp_1_dump.sql

note that there is no space beetwen -uroot and -p246passwd

a sql file should be on /home/rootzone now, that’s the dump or backup file

2. Restore mySQL database from dump file

Now how to restore mySQL database from mySQL dump file that we had from the first step to other server from console ?

Enter console as root and create a database (recommended) you create database named exactly like databse on server A. Let say your mySQL  password is “2403″ and you’ve already copy wp_1_dump.sql to /home/serverb/

# mysql -uroot -p2403
> create database wp_1;

Database wp_1 is created. Now quit first from mySQL

> quit

On console, enter this command :

# mysql -uroot -p2403 wp_1 < /home/serverb/wp_1_dump.sql

Done, you are already restore your mySQL database

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment