天天看點

mysql dump使用執行個體

Examples

To make a backup of an entire database:

shell> mysqldump db_name > backup-file.sql
           

To load the dump file back into the server:

shell> mysql db_name < backup-file.sql
           

Another way to reload the dump file:

shell> mysql -e "source /path-to-backup/backup-file.sql" db_name
           

mysqldump is also very useful for populating databases by copying data from one MySQL server to another:

You can dump several databases with one command:

shell> mysqldump --databases db_name1 [db_name2 ...] > my_databases.sql
           

To dump all databases, use the –all-databases option:

For InnoDB tables, mysqldump provides a way of making an online backup:

shell> mysqldump --all-databases --master-data --single-transaction > all_databases.sql
           

This backup acquires a global read lock on all tables (using FLUSH TABLES WITH READ LOCK) at the beginning of the dump. As soon as this lock has been acquired, the binary log coordinates are read and the lock is released. If long updating statements are running when the FLUSH statement is issued, the MySQL server may get stalled until those statements finish. After that, the dump becomes lock free and does not disturb reads and writes on the tables. If the update statements that the MySQL server receives are short (in terms of execution time), the initial lock period should not be noticeable, even with many updates.

For point-in-time recovery (also known as “roll-forward,” when you need to restore an old backup and replay the changes that happened since that backup), it is often useful to rotate the binary log (see Section 6.4.4, “The Binary Log”) or at least know the binary log coordinates to which the dump corresponds:

shell> mysqldump --all-databases --master-data= > all_databases.sql
           

Or:

shell> mysqldump --all-databases --flush-logs --master-data=
              > all_databases.sql
           

繼續閱讀