mysqldump备份数据库与命令选项

mysqldump命令使用
该工具在mysql安装根目录下的bin/里面。
1、服务器间复制
#mysqldump --host=server1 test t1 | mysql --host=server2 test
2、备份所有的数据库
#mysqldum --all-database > dum.sql
3 、备份单个数据库
#mysqldump --database test > test.sql
或者
#mysqldump  test > test.sql
4、备份单张数据表
#mysqldump test t1 > test_t1.sql

mysql命令选项很多,可以通过#msqldump --help查看所有的选项。以下两个选项对数据库备份维护数据的一致性和数据恢复很重要。
--master-data[=#]   
This causes the binary log position and filename to be appended to the output. If equal to 1, will print it as a CHANGE MASTER command; if equal to 2, that command will be prefixed with a comment symbol. This option will turn --lock-all-tables on, unless --single-transaction is specified too (in which case a global read lock is only taken a short time at the beginning of the dump - don't forget to read about --single-transaction below). In all cases any action on logs will happen at the exact moment of the dump.Option automatically turns --lock-tables off.
启用该参数时,增加当前备份时binlog文件名和偏移量到备份文件中。
--master-data=1,添加的内容为CHANGE MASTER命令。如,CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000026', MASTER_LOG_POS=107;
--master-data=2,添加的内容为CHANGE MASTER命令的注释。如, -- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000026', MASTER_LOG_POS=107;
如果mysqldump没有设置该参数,上面的内容都不会存在。
启用该选项,在dump之前会加上一个--lock-all-tables锁。除非同时启用了--single-transactions,这种情况下会加一个全局读锁。该选项会自动关闭--lock-tables锁。

--single-transaction 
Creates a consistent snapshot by dumping all tables in a  single transaction. Works ONLY for tables stored in storage engines which support multiversioning (currently only InnoDB does); the dump is NOT guaranteed to be consistent for other storage engines. While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log position), no other connection should use the following
statements: ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not isolated from them. Option automatically turns off --lock-tables.
该选项会在同一个事务内创建一个所有数据表一致性快照。该选项仅对支持多版本并发控制(multiversioning,MVCC,MultiVersion Concurrency Control)的存储引擎有效,因而目前仅支持InnoDB存储引擎。使用该选项时,其它连接最好不要使用ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABL语句,一致性快照没有隔离这些命令操作。该选项也会自动关闭--lock-tables锁。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值