文章目录
mysqldump 的几个主要选项
1. --lock-tables
Lock all tables for read.
(Defaults to on; use --skip-lock-tables to disable.)
14777 Query /*!40100 SET @@SQL_MODE='' */
14777 Init DB db1
14777 Query SHOW CREATE DATABASE IF NOT EXISTS `db1`
14777 Query show tables
14777 Query LOCK TABLES `t` READ /*!32311 LOCAL */
14777 Query show table status like 't'
14777 Query SET SQL_QUOTE_SHOW_CREATE=1
14777 Query SET SESSION character_set_results = 'binary'
14777 Query show create table `t`
14777 Query SET SESSION character_set_results = 'utf8'
14777 Query show fields from `t`
14777 Query show fields from `t`
14777 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `t`
14777 Query SET SESSION character_set_results = 'binary'
14777 Query use `db1`
14777 Query select @@collation_database
14777 Query SHOW TRIGGERS LIKE 't'
14777 Query SET SESSION character_set_results = 'utf8'
14777 Query UNLOCK TABLES
14777 Quit
2. --lock-all-tables
发起一个全局的读锁,阻止对所有表的写入操作,以此来确保数据的一致性。备份完成后,该会话断开,会自动解锁。
Locks all tables across all databases. This is achieved
by taking a global read lock for the duration of the
whole dump. Automatically turns --single-transaction and
–lock-tables off.
14778 Query /*!40100 SET @@SQL_MODE='' */
14778 Query /*!40103 SET TIME_ZONE='+00:00' */
14778 Query FLUSH TABLES
14778 Query FLUSH TABLES WITH READ LOCK
14778 Query SHOW VARIABLES LIKE 'gtid\_mode'
14778 Query SELECT @@GLOBAL.GTID_EXECUTED
14778 Init DB db1
14778 Query SHOW TABLES LIKE 't'
14778 Query show table