当前位置: 首页 > 图文教程 > 数据库 > MYSQL > MySQL备份--使用mysqldump全备

MYSQL
Mysql教程:如何修改默认密码
SQL Server教程:三种导入导出数据使用方式比较
Mysql技巧:指定只监听某个特定地址的设置方法
Mysql教程:1067错误解决方法
解决Mysql 错误:cannot create windows service for
解决Mysql连接过多错误的方法
Mysql教程:数据库字符替换和replace函数的使用
Mysql教程:性能跟踪语句
Mysql教程:对MySQL中的锁机制的总结
Mysql教程:介绍TIMESTAMP时间戳的使用
Mysql教程:将txt文本中的数据轻松导入MySQL表中的方法
MySQL:小编浅谈MySQL中的Geometry类
大型门户网站架构设计的可伸缩性
MYSQL教程:缓慢的drop table 操作
优化SQL语句需要注意的4点
MySQL前途难料开源数据库下一个领袖是谁?
网站Access数据库文件更安全的3种措施
sql xml入门:xpath和xquery
QA里执行sp_attach_db出现错误1813
MySQL中文模糊检索问题解决方法

MYSQL 中的 MySQL备份--使用mysqldump全备


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 372 ::
收藏到网摘: n/a

全备?个人理解是数据在备份时间点保持数据一致性。
这样就涉及到全局锁问题。(东西从官方cp的)
值得关注的几个mysqldump参数:
--lock-all-tables, -x 
Lock all tables across all databases. This is achieved by acquiring a global read lock for the duration of the whole dump. This option automatically turns off --single-transaction and --lock-tables.
 
--flush-logs, -F 
Flush the MySQL server log files before starting the dump. This option requires the RELOAD privilege. Note that if you use this option in combination with the --all-databases (or -A) option, the logs are flushed for each database dumped. The exception is when using --lock-all-tables or --master-data: In this case, the logs are flushed only once, corresponding to the moment that all tables are locked. If you want your dump and the log flush to happen at exactly the same moment, you should use --flush-logs together with either --lock-all-tables or --master-data.
 
--master-data[=value]
value默认为1;区别如下: 
--master-data=1
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000019', MASTER_LOG_POS=191;
--master-data=2 
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000019', MASTER_LOG_POS=191;
Use this option to dump a master replication server to produce a dump file that can be used to set up another server as a slave of the master. It causes the dump output to include a CHANGE MASTER TO statement that indicates the binary log coordinates (file name and position) of the dumped server. These are the master server coordinates from which the slave should start replicating. 
If the option value is 2, the CHANGE MASTER TO statement is written as an SQL comment, and thus is informative only; it has no effect when the dump file is reloaded. If the option value is 1, the statement takes effect when the dump file is reloaded. If the option value is not specified, the default value is 1. 
This option requires the RELOAD privilege and the binary log must be enabled. 
The --master-data option automatically turns off --lock-tables. It also turns on --lock-all-tables, unless --single-transaction also is specified, in which case, a global read lock is acquired only for a short time at the beginning of the dump (see the description for --single-transaction). In all cases, any action on logs happens at the exact moment of the dump. 
It is also possible to set up a slave by dumping an existing slave of the master. To do this, use the following procedure on the existing slave: 
(从已经存在的从库做多从,是不错的选择)
Stop the slave's SQL thread and get its current status: 
mysql> STOP SLAVE SQL_THREAD;
mysql> SHOW SLAVE STATUS;
From the output of the SHOW SLAVE STATUS statement, get the binary log coordinates of the master server from which the new slave should start replicating. These coordinates are the values of the Relay_Master_Log_File and Exec_Master_Log_Pos values. Denote those values as file_name and file_pos. 
Dump the slave server: 
shell> mysqldump --master-data=2 --all-databases > dumpfile
Restart the slave: 
mysql> START SLAVE;
On the new slave, reload the dump file: 
shell> mysql < dumpfile
On the new slave, set the replication coordinates to those of the master server obtained earlier: 
mysql> CHANGE MASTER TO
  -> MASTER_LOG_FILE = 'file_name', MASTER_LOG_POS = file_pos;
The CHANGE MASTER TO statement might also need other parameters, such as MASTER_HOST to point the slave to the correct master server host. Add any such parameters as necessary.
 
--single-transaction 对于InnoDB
This option issues a BEGIN SQL statement before dumping data from the server. It is useful only with transactional tables such as InnoDB, because then it dumps the consistent state of the database at the time when BEGIN was issued without blocking any applications. 
When using this option, you should keep in mind that only InnoDB tables are dumped in a consistent state. For example, any MyISAM or MEMORY tables dumped while using this option may still change state. 
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. A consistent read is not isolated from those statements, so use of them on a table to be dumped can cause the SELECT performed by mysqldump to retrieve the table contents to obtain incorrect contents or fail. 
This option is not supported for MySQL Cluster tables; the results cannot be guaranteed to be consistent due to the fact that the NDBCLUSTER storage engine supports only the READ_COMMITTED transaction isolation level. You should always use NDB backup and restore instead. 
The --single-transaction option and the --lock-tables option are mutually exclusive, because LOCK TABLES causes any pending transactions to be committed implicitly. 
To dump large tables, you should combine this option with --quick.