martedì 9 agosto 2011

mysqldump


The most simple way is to issue this command:
mysqldump -u [user] -p [database_name] > [backupfile].dump
This command is going to ask you for the [user] password and then will create a script which later can be used to retore the data.
Another way is to use the optimized way.
mysqldump --opt -u [user_name] -p [database_name] > [backup_file].dump
This command will use an optimized method, and will include in the script MySQL commands that will erase (drop) tables that already exists and create them again before populate the data inside.
Maybe the best way to run this command is to use the option of gzip the output file. (for obvious reasons)
Once you have your backup file, you may want to restore it someday, this is the way to do it. (remember tu unzip your file, if zipped, before)
mysql [database_name] < [backup_file].dump
Remeber that you can run
man mysqldump
for more help.

Backuping a single table from a database
mysqldump -u user_name -p database_name table_name > /var/www/backups/table_name.sql
Restoring the table into another database
mysql -u -p database_name < /var/www/backups/table_name.sql

Nessun commento:

Posta un commento