Difference between revisions of "Backing up and restoring MySQL database"

From Notes_Wiki
(Created page with "=Backing up and restoring MySQL database= ==MySQL database backup== To backup MySQL database one can use '<tt>mysqldump</tt>' program. Syntax for mysqldump is: <pre> mysqldu...")
 
m
Line 26: Line 26:
bunzip2 -c <dump_file>.sql.bz2 | sshpass -p <mysql_database_password> mysql -u <mysql_username> -p <database_name>
bunzip2 -c <dump_file>.sql.bz2 | sshpass -p <mysql_database_password> mysql -u <mysql_username> -p <database_name>
</pre>
</pre>
Back to [[Mysql configuration]]

Revision as of 23:09, 17 November 2012

Backing up and restoring MySQL database

MySQL database backup

To backup MySQL database one can use 'mysqldump' program. Syntax for mysqldump is:

mysqldump -u <mysql_username> -p <database_name> > <database_name>.sql

To automatically compress the database before it is stored on disk the output of mysqldump can be passed through bzip2 as:

mysqldump -u <mysql_username> -p <database_name> | bzip2 > <database_name>.sql.bz2


Restoring MySQL database

To restore MySQL database we can use 'mysql' command line client. Command to restore database is:

cat <dump_file>.sql | mysql -u <mysql_username> -p <database_name>


To restore a compressed database along with password we can take help of 'bunzip2' and 'sshpass' utilities in following manner:

bunzip2 -c <dump_file>.sql.bz2 | sshpass -p <mysql_database_password> mysql -u <mysql_username> -p <database_name>


Back to Mysql configuration