08.14 self-summary
Backup of the database
A backup of the database
1. Single database backup
mysqldump -uroot -p123 db1 > db1.sql #库名
mysqldump -uroot -p123 db1 table1 table2 > db1-table1-table2.sql #库名 表名
2. Multi-database backup
mysqldump -uroot -p123 --databases db1 db2 mysql db3 > db1_db2_mysql_db3.sql
3. Back up all libraries
mysqldump -uroot -p123 --all-databases > all.sql
II. Backup Recovery
1. Quit database
mysql -u -p < filename.sql;
2. Within the database
- Create an empty database
- Select Database
- Then source filename; to restore
E.g
use db1;
source /root/db1.sql
III. Database Migration
务必保证在相同版本之间迁移
# mysqldump -h 源IP -uroot -p123 --databases db1 | mysql -h 目标IP -uroot -p456
IV. Backup higher order
1. Common parameters
- -B: it is represented specify multiple libraries, an increase of building a database statements and statements use the database.
- -compact: uncommented for debug output is not suitable for use in a production environment.
- -A: it represents the duty of all the libraries.
- -F: Refresh binlog log, facilitate incremental recovery.
- -master-data: increase binlog log file name and location corresponding to the point.
- -x, -lock-all-tables: Table were locked at the time of the backup, maintaining data consistency.
- -d: only backup structure of the table.
- -t: back up only the data in the database
- -single-transaction for backup innodb database.
2.-B backup
Single Library
备份test中的所有表
mysqldump -uroot -ppassword -B test >/tmp/test.sql
Multi-database
mysqldump -uroot -ppassword -B 库1 库2 >/tmp/test.sql
3. gzip compressed data backup
mysqldump -uroot -ppassword -B 库1 库2 |gzip >/tmp/test.gz
Cutting binlog log :( 4. incremental backups when the backup time can be used)
-F 的作用就是备份数据库的时候,将binlog日志进行重新刷新。
mysqldump -uroot -ppassword -t -B -F test
5. Back up time will be recorded and mysqlbinglog location specified file file name
--master-data=1 的作用就是备份数据库的时候,将binlog日志进行重新刷新
mysqldump -uroot -ppassword -t -B -F --master-data test