Backup and Restore MySQL Database
October 7th, 2006 liewsheng Posted in Admin, mysql, mysqldump | Hits: 6372 |
Last month when my web server (whic is now host this page ;p) is crash, I was so sad and have to setup the server again :( It take a lot of time to setup this server again, lucky I have backup the MySQL database and able to retrieve back ;)
To Backup the MySQL DB, it just a simple command:
mysqldump --add-drop-table -u user --password=mypassword database> lbesql
–add-drop-table switch will drop the database table before create it again, -u is the username for the MySQL administrator, -p is to tell mysql to prompt you (thanks to aizatto for the correction :D) and of cause –password is the password for the user.
So from now on, i have using a cron job to do the jobs for me ;p For more information on how to create a backup script can refer to Wordpress MySQL backup script or Backing Up Your Database
So how to restore back the backup DB? It is easy:
mysql -u user -p -Ddatabase --password=mypassword < lbesql
after you have enter the command, of it will ask you the password, just give it the password and wahla…the DB is restore back :) more detail on how to retrieve back the database can refer to Restoring Back Your Database.
Live Chat!









October 19th, 2006 at 7:00 am
Actually you shouldnt include the arguments “–password=” as your leaving it in CLEARTEXT for people to see. That’s insane!
Your commands should be:
And it’ll prompt you for the password. The “-p” argument is the option so that it prompts you, not the database you want to dump or restore.
October 21st, 2006 at 10:17 pm
yeah i do agree with you, is there have another ways to do provide password in secure way?
har…you are correct, the -p will prompt you to enter password (if the user have password protected)
Thanks aizatto, for the correction!!! :)
July 30th, 2007 at 3:55 pm
how to configure vpn in linux
October 26th, 2007 at 8:53 pm
It works easy and fast. Thanks from a newbie of Linux ;)
November 1st, 2007 at 11:21 pm
[...] sure you backup your mysql database, wordpress folder weekly to other places, you don’t want to lose your data, if anythings [...]