Saturday, 25 July 2015

Mysql Backup and Restore command for linux


Backup MySQL DB
In order to take a backup of MySQL database,first you need to make sure that required database is present in database server and you have a required access to it.

The following command is used to take an backup:

mysqldump -u[username] -p[password] [database name] > [file name.sql]

for ex: mysqldump -uroot -prootDB mydb>/exports/db/mysql.sql


If you want to take an backup of all databases present in database server,then use following command:

mysqldump -uroot -prootDB --all-databases>/exports/db/allmysql.sql


To take a backup of mysql procedures ,functions along with tables,use this command:

mysqldump -uroot -prootDB --routines mydb>/exports/db/mysql.sql

Restore MySQL DB

To restore the database use this command:

mysql -u[username] -p[password] [database name] < [file name.sql]

for ex: mysql -uroot -prootDB mydb</exports/db/mysql.sql



In case of any doubt,please post a question.







No comments:

Post a Comment