mysqldump 原理

(3)分析general.log日志:

[root@zstedu data]# cat zstedu.log

mysqld, Version: 5.7.22-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306 Unix socket: /tmp/mysql3306.sock
Time Id Command Argument
2018-07-25T23:22:35.427394Z 6 Quit
2018-07-25T23:22:43.863610Z 7 Connect root@localhost on using Socket


2018-07-25T23:22:43.864323Z 7 Query /*!40100 SET @@SQL_MODE='' */


2018-07-25T23:22:43.865639Z 7 Query /*!40103 SET TIME_ZONE='+00:00' */


2018-07-25T23:22:43.866240Z 7 Query FLUSH /*!40101 LOCAL */ TABLES

关闭所有打开的表,如果表正在使用就强制关闭,并且刷新 cache,防止有在进行 DDL 操作,并拿到metadata lock
2018-07-25T23:22:43.870798Z 7 Query FLUSH TABLES WITH READ LOCK

执行flush tables 操作,并添加一个全局读锁,阻止commit,获得 db 一致性状态。FTWRL让整个实例只读,不支持写入,短暂的一致性;
2018-07-25T23:22:43.871222Z 7 Query SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ

设置当前会话的事务隔离级别为 RR,开启一个一致性快照。RR 可避免不可重复读和换读。以确保备份事务中任何时刻的数据都相同。
2018-07-25T23:22:43.871572Z 7 Query START TRANSACTION /*!40100 WITH CONSISTENT SNAPSHOT */

获取当前数据库的快照,这个是由mysqldump--single-transaction决定的。 只适用于支持事务的表。
/*!40100*/表示主版本大于 4,小版本大于 01 这个 with consistent snapshot语法才能生效; 如果不满足版本要求,那么with consistent snapshot语法是不生效的,只会执行start transaction,不会执行 withconsistent snapshot 。
2018-07-25T23:22:43.872086Z 7 Query SHOW VARIABLES LIKE 'gtid\_mode'


2018-07-25T23:22:43.886945Z 7 Query SELECT @@GLOBAL.GTID_EXECUTED

获取已经执行过的 GTID 值
2018-07-25T23:22:43.887336Z 7 Query SHOW MASTER STATUS

这个是由于--master-data=2决定的,记录了开始备份时,binlog 的状态信息,包括MASTER_LOG_FILE 和 MASTER_LOG_POS
2018-07-25T23:22:43.887711Z 7 Query UNLOCK TABLES

释放锁。这一步解锁只是解锁的上面第(2)步 flush tables with read lock操作,读还是在第(4)步的事务下面读的。备份完非 innodb 的数据后,再将锁释放UNLOCK TABLES。后面开始备份innodb的数据。
为什么在备份 innodb 表之前,就已经将锁释放掉了呢?
因为这实际上是利用了 innodb 引擎的 MVCC 机制,开启快照读后,就能获得那个时间的一致性数据,无论备份多长时间,直到整个事务结束(commit)为止。
假如我 4 点开始执行备份,6 点完成备份。那么这些数据其实还是 4 点之前的数据。4 点--6 点的数据是不会备份的。
2018-07-25T23:22:43.888218Z 7 Query SELECT LOGFILE_GROUP_NAME, FILE_NAME, TOTAL_EXTENTS, INITIAL_SIZE, ENGINE, EXTRA FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'UNDO LOG' AND FILE_NAME IS NOT NULL AND LOGFILE_GROUP_NAME IS NOT NULL GROUP BY LOGFILE_GROUP_NAME, FILE_NAME, ENGINE, TOTAL_EXTENTS, INITIAL_SIZE ORDER BY LOGFILE_GROUP_NAME
2018-07-25T23:22:43.889534Z 7 Query SELECT DISTINCT TABLESPACE_NAME, FILE_NAME, LOGFILE_GROUP_NAME, EXTENT_SIZE, INITIAL_SIZE, ENGINE FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'DATAFILE' ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME  NDB引擎,不使用
2018-07-25T23:22:43.891193Z 7 Query SHOW DATABASES


2018-07-25T23:22:43.891868Z 7 Query SHOW VARIABLES LIKE 'ndbinfo\_version'


2018-07-25T23:22:43.894213Z 7 Init DB mysql


2018-07-25T23:22:43.894352Z 7 Query SHOW CREATE DATABASE IF NOT EXISTS `mysql`


2018-07-25T23:22:43.894473Z 7 Query SAVEPOINT sp

断点,创建一个标签位即还原点。
在开始做所有的事情之前创建了一个事务的还原点,然后先备份一张表,然后再回到事务的还原点,再继续备份下一张表,一直这样重复直到所有的表备份完成。最后把事务还原点释放掉。然后把这个事务 rollback 掉就可以了。


2018-07-25T23:22:43.894593Z 7 Query show tables
2018-07-25T23:22:43.895353Z 7 Query show table status like 'columns\_priv'
2018-07-25T23:22:43.896561Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.896718Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.896858Z 7 Query show create table `columns_priv`
2018-07-25T23:22:43.897015Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.897216Z 7 Query show fields from `columns_priv`
2018-07-25T23:22:43.898077Z 7 Query show fields from `columns_priv`
2018-07-25T23:22:43.898661Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `columns_priv`
2018-07-25T23:22:43.899046Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.899213Z 7 Query use `mysql`
2018-07-25T23:22:43.899345Z 7 Query select @@collation_database
2018-07-25T23:22:43.899590Z 7 Query SHOW TRIGGERS LIKE 'columns\_priv'
2018-07-25T23:22:43.900534Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.900678Z 7 Query ROLLBACK TO SAVEPOINT sp  断点结束,返回上一开始位置
2018-07-25T23:22:43.900800Z 7 Query show table status like 'db'
2018-07-25T23:22:43.901460Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.901566Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.901670Z 7 Query show create table `db`
2018-07-25T23:22:43.901903Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.902036Z 7 Query show fields from `db`
2018-07-25T23:22:43.902686Z 7 Query show fields from `db`
2018-07-25T23:22:43.903340Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `db`
2018-07-25T23:22:43.903621Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.903722Z 7 Query use `mysql`
2018-07-25T23:22:43.903889Z 7 Query select @@collation_database
2018-07-25T23:22:43.904022Z 7 Query SHOW TRIGGERS LIKE 'db'
2018-07-25T23:22:43.904512Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.904617Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.904725Z 7 Query show table status like 'engine\_cost'
2018-07-25T23:22:43.905241Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.905445Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.905554Z 7 Query show create table `engine_cost`
2018-07-25T23:22:43.905699Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.905842Z 7 Query show fields from `engine_cost`
2018-07-25T23:22:43.906307Z 7 Query show fields from `engine_cost`
2018-07-25T23:22:43.906758Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `engine_cost`
2018-07-25T23:22:43.907301Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.907427Z 7 Query use `mysql`
2018-07-25T23:22:43.907542Z 7 Query select @@collation_database
2018-07-25T23:22:43.907673Z 7 Query SHOW TRIGGERS LIKE 'engine\_cost'
2018-07-25T23:22:43.908452Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.908633Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.908759Z 7 Query show table status like 'event'
2018-07-25T23:22:43.909501Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.909617Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.909721Z 7 Query show create table `event`
2018-07-25T23:22:43.910143Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.910300Z 7 Query show fields from `event`
2018-07-25T23:22:43.911092Z 7 Query show fields from `event`
2018-07-25T23:22:43.911730Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `event`
2018-07-25T23:22:43.912019Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.912128Z 7 Query use `mysql`
2018-07-25T23:22:43.912237Z 7 Query select @@collation_database
2018-07-25T23:22:43.912359Z 7 Query SHOW TRIGGERS LIKE 'event'
2018-07-25T23:22:43.912912Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.913025Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.913135Z 7 Query show table status like 'func'
2018-07-25T23:22:43.913661Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.913759Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.913911Z 7 Query show create table `func`
2018-07-25T23:22:43.914054Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.914167Z 7 Query show fields from `func`
2018-07-25T23:22:43.914601Z 7 Query show fields from `func`
2018-07-25T23:22:43.915103Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `func`
2018-07-25T23:22:43.915284Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.915383Z 7 Query use `mysql`
2018-07-25T23:22:43.915485Z 7 Query select @@collation_database
2018-07-25T23:22:43.915602Z 7 Query SHOW TRIGGERS LIKE 'func'
2018-07-25T23:22:43.916132Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.916243Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.916351Z 7 Query show table status like 'help\_category'
2018-07-25T23:22:43.916789Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.916939Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.917047Z 7 Query show create table `help_category`
2018-07-25T23:22:43.917185Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.917298Z 7 Query show fields from `help_category`
2018-07-25T23:22:43.917722Z 7 Query show fields from `help_category`
2018-07-25T23:22:43.918214Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `help_category`
2018-07-25T23:22:43.918586Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.918686Z 7 Query use `mysql`
2018-07-25T23:22:43.918789Z 7 Query select @@collation_database
2018-07-25T23:22:43.918960Z 7 Query SHOW TRIGGERS LIKE 'help\_category'
2018-07-25T23:22:43.919436Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.919539Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.919645Z 7 Query show table status like 'help\_keyword'
2018-07-25T23:22:43.920137Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.920219Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.920297Z 7 Query show create table `help_keyword`
2018-07-25T23:22:43.920399Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.920486Z 7 Query show fields from `help_keyword`
2018-07-25T23:22:43.920850Z 7 Query show fields from `help_keyword`
2018-07-25T23:22:43.921183Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `help_keyword`
2018-07-25T23:22:43.922446Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.922540Z 7 Query use `mysql`
2018-07-25T23:22:43.922625Z 7 Query select @@collation_database
2018-07-25T23:22:43.922724Z 7 Query SHOW TRIGGERS LIKE 'help\_keyword'
2018-07-25T23:22:43.923173Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.923255Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.923341Z 7 Query show table status like 'help\_relation'
2018-07-25T23:22:43.923771Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.923872Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.923952Z 7 Query show create table `help_relation`
2018-07-25T23:22:43.924061Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.924153Z 7 Query show fields from `help_relation`
2018-07-25T23:22:43.924523Z 7 Query show fields from `help_relation`
2018-07-25T23:22:43.925013Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `help_relation`
2018-07-25T23:22:43.926640Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.926727Z 7 Query use `mysql`
2018-07-25T23:22:43.926845Z 7 Query select @@collation_database
2018-07-25T23:22:43.926947Z 7 Query SHOW TRIGGERS LIKE 'help\_relation'
2018-07-25T23:22:43.927358Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.927440Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.927525Z 7 Query show table status like 'help\_topic'
2018-07-25T23:22:43.927935Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.928015Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.928093Z 7 Query show create table `help_topic`
2018-07-25T23:22:43.928204Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.928292Z 7 Query show fields from `help_topic`
2018-07-25T23:22:43.928645Z 7 Query show fields from `help_topic`
2018-07-25T23:22:43.929041Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `help_topic`
2018-07-25T23:22:43.948752Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.948877Z 7 Query use `mysql`
2018-07-25T23:22:43.948974Z 7 Query select @@collation_database
2018-07-25T23:22:43.949085Z 7 Query SHOW TRIGGERS LIKE 'help\_topic'
2018-07-25T23:22:43.949567Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.949650Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.949739Z 7 Query show table status like 'innodb\_index\_stats'
2018-07-25T23:22:43.950189Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.950270Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.950348Z 7 Query show create table `innodb_index_stats`
2018-07-25T23:22:43.950466Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.950558Z 7 Query show fields from `innodb_index_stats`
2018-07-25T23:22:43.950988Z 7 Query show fields from `innodb_index_stats`
2018-07-25T23:22:43.951371Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `innodb_index_stats`
2018-07-25T23:22:43.951593Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.951672Z 7 Query use `mysql`
2018-07-25T23:22:43.951753Z 7 Query select @@collation_database
2018-07-25T23:22:43.951888Z 7 Query SHOW TRIGGERS LIKE 'innodb\_index\_stats'
2018-07-25T23:22:43.952281Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.952451Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.952541Z 7 Query show table status like 'innodb\_table\_stats'
2018-07-25T23:22:43.952914Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.952988Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.953065Z 7 Query show create table `innodb_table_stats`
2018-07-25T23:22:43.953175Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.953264Z 7 Query show fields from `innodb_table_stats`
2018-07-25T23:22:43.953616Z 7 Query show fields from `innodb_table_stats`
2018-07-25T23:22:43.954018Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `innodb_table_stats`
2018-07-25T23:22:43.954206Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.954284Z 7 Query use `mysql`
2018-07-25T23:22:43.954364Z 7 Query select @@collation_database
2018-07-25T23:22:43.954456Z 7 Query SHOW TRIGGERS LIKE 'innodb\_table\_stats'
2018-07-25T23:22:43.954865Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.954957Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.955041Z 7 Query show table status like 'ndb\_binlog\_index'
2018-07-25T23:22:43.955446Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.955521Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.955597Z 7 Query show create table `ndb_binlog_index`
2018-07-25T23:22:43.955706Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.955794Z 7 Query show fields from `ndb_binlog_index`
2018-07-25T23:22:43.956227Z 7 Query show fields from `ndb_binlog_index`
2018-07-25T23:22:43.956615Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `ndb_binlog_index`
2018-07-25T23:22:43.956761Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.956881Z 7 Query use `mysql`
2018-07-25T23:22:43.957026Z 7 Query select @@collation_database
2018-07-25T23:22:43.957122Z 7 Query SHOW TRIGGERS LIKE 'ndb\_binlog\_index'
2018-07-25T23:22:43.957499Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.957579Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.957661Z 7 Query show table status like 'plugin'
2018-07-25T23:22:43.958047Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.958127Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.958203Z 7 Query show create table `plugin`
2018-07-25T23:22:43.958306Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.958393Z 7 Query show fields from `plugin`
2018-07-25T23:22:43.958709Z 7 Query show fields from `plugin`
2018-07-25T23:22:43.959091Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `plugin`
2018-07-25T23:22:43.959253Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.959331Z 7 Query use `mysql`
2018-07-25T23:22:43.959411Z 7 Query select @@collation_database
2018-07-25T23:22:43.959501Z 7 Query SHOW TRIGGERS LIKE 'plugin'
2018-07-25T23:22:43.959927Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.960013Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.960096Z 7 Query show table status like 'proc'
2018-07-25T23:22:43.960501Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.960576Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.960653Z 7 Query show create table `proc`
2018-07-25T23:22:43.960784Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.961061Z 7 Query show fields from `proc`
2018-07-25T23:22:43.961655Z 7 Query show fields from `proc`
2018-07-25T23:22:43.962189Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `proc` WHERE db != 'sys'
2018-07-25T23:22:43.962543Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.962632Z 7 Query use `mysql`
2018-07-25T23:22:43.962716Z 7 Query select @@collation_database
2018-07-25T23:22:43.962830Z 7 Query SHOW TRIGGERS LIKE 'proc'
2018-07-25T23:22:43.963240Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.963321Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.963407Z 7 Query show table status like 'procs\_priv'
2018-07-25T23:22:43.963879Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.963971Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.964052Z 7 Query show create table `procs_priv`
2018-07-25T23:22:43.964170Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.964261Z 7 Query show fields from `procs_priv`
2018-07-25T23:22:43.964652Z 7 Query show fields from `procs_priv`
2018-07-25T23:22:43.965079Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `procs_priv`
2018-07-25T23:22:43.965225Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.965303Z 7 Query use `mysql`
2018-07-25T23:22:43.965384Z 7 Query select @@collation_database
2018-07-25T23:22:43.965476Z 7 Query SHOW TRIGGERS LIKE 'procs\_priv'
2018-07-25T23:22:43.965894Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.965980Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.966064Z 7 Query show table status like 'proxies\_priv'
2018-07-25T23:22:43.966469Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.966543Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.966620Z 7 Query show create table `proxies_priv`
2018-07-25T23:22:43.966729Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.966850Z 7 Query show fields from `proxies_priv`
2018-07-25T23:22:43.967218Z 7 Query show fields from `proxies_priv`
2018-07-25T23:22:43.967575Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `proxies_priv`
2018-07-25T23:22:43.967730Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.967842Z 7 Query use `mysql`
2018-07-25T23:22:43.967933Z 7 Query select @@collation_database
2018-07-25T23:22:43.968025Z 7 Query SHOW TRIGGERS LIKE 'proxies\_priv'
2018-07-25T23:22:43.968392Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.968471Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.968553Z 7 Query show table status like 'server\_cost'
2018-07-25T23:22:43.968977Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.969057Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.969134Z 7 Query show create table `server_cost`
2018-07-25T23:22:43.969240Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.969327Z 7 Query show fields from `server_cost`
2018-07-25T23:22:43.969723Z 7 Query show fields from `server_cost`
2018-07-25T23:22:43.970100Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `server_cost`
2018-07-25T23:22:43.970296Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.970373Z 7 Query use `mysql`
2018-07-25T23:22:43.970453Z 7 Query select @@collation_database
2018-07-25T23:22:43.970544Z 7 Query SHOW TRIGGERS LIKE 'server\_cost'
2018-07-25T23:22:43.970956Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.971041Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.971122Z 7 Query show table status like 'servers'
2018-07-25T23:22:43.971465Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.971538Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.971614Z 7 Query show create table `servers`
2018-07-25T23:22:43.971725Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.971846Z 7 Query show fields from `servers`
2018-07-25T23:22:43.972220Z 7 Query show fields from `servers`
2018-07-25T23:22:43.972585Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `servers`
2018-07-25T23:22:43.972741Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.972853Z 7 Query use `mysql`
2018-07-25T23:22:43.972942Z 7 Query select @@collation_database
2018-07-25T23:22:43.973089Z 7 Query SHOW TRIGGERS LIKE 'servers'
2018-07-25T23:22:43.973459Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.973539Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.973620Z 7 Query show table status like 'slave\_master\_info'
2018-07-25T23:22:43.974174Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.974262Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.974343Z 7 Query show create table `slave_master_info`
2018-07-25T23:22:43.974487Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.974579Z 7 Query show fields from `slave_master_info`
2018-07-25T23:22:43.975138Z 7 Query show fields from `slave_master_info`
2018-07-25T23:22:43.975608Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.975688Z 7 Query use `mysql`
2018-07-25T23:22:43.975769Z 7 Query select @@collation_database
2018-07-25T23:22:43.975905Z 7 Query SHOW TRIGGERS LIKE 'slave\_master\_info'
2018-07-25T23:22:43.976279Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.976358Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.976440Z 7 Query show table status like 'slave\_relay\_log\_info'
2018-07-25T23:22:43.976777Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.976891Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.976975Z 7 Query show create table `slave_relay_log_info`
2018-07-25T23:22:43.977088Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.977257Z 7 Query show fields from `slave_relay_log_info`
2018-07-25T23:22:43.977623Z 7 Query show fields from `slave_relay_log_info`
2018-07-25T23:22:43.978000Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.978080Z 7 Query use `mysql`
2018-07-25T23:22:43.978159Z 7 Query select @@collation_database
2018-07-25T23:22:43.978250Z 7 Query SHOW TRIGGERS LIKE 'slave\_relay\_log\_info'
2018-07-25T23:22:43.978611Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.978691Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.978772Z 7 Query show table status like 'slave\_worker\_info'
2018-07-25T23:22:43.979154Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.979233Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.979309Z 7 Query show create table `slave_worker_info`
2018-07-25T23:22:43.979425Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.979513Z 7 Query show fields from `slave_worker_info`
2018-07-25T23:22:43.979951Z 7 Query show fields from `slave_worker_info`
2018-07-25T23:22:43.980351Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `slave_worker_info`
2018-07-25T23:22:43.980517Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.980594Z 7 Query use `mysql`
2018-07-25T23:22:43.980673Z 7 Query select @@collation_database
2018-07-25T23:22:43.980762Z 7 Query SHOW TRIGGERS LIKE 'slave\_worker\_info'
2018-07-25T23:22:43.981175Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.981260Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.981342Z 7 Query show table status like 'tables\_priv'
2018-07-25T23:22:43.981825Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.981907Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.981985Z 7 Query show create table `tables_priv`
2018-07-25T23:22:43.982124Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.982215Z 7 Query show fields from `tables_priv`
2018-07-25T23:22:43.982613Z 7 Query show fields from `tables_priv`
2018-07-25T23:22:43.983135Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `tables_priv`
2018-07-25T23:22:43.983332Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.983411Z 7 Query use `mysql`
2018-07-25T23:22:43.983583Z 7 Query select @@collation_database
2018-07-25T23:22:43.983684Z 7 Query SHOW TRIGGERS LIKE 'tables\_priv'
2018-07-25T23:22:43.984097Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.984178Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.984262Z 7 Query show table status like 'time\_zone'
2018-07-25T23:22:43.984610Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.984683Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.984759Z 7 Query show create table `time_zone`
2018-07-25T23:22:43.984964Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.985060Z 7 Query show fields from `time_zone`
2018-07-25T23:22:43.985382Z 7 Query show fields from `time_zone`
2018-07-25T23:22:43.985700Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `time_zone`
2018-07-25T23:22:43.985891Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.985973Z 7 Query use `mysql`
2018-07-25T23:22:43.986053Z 7 Query select @@collation_database
2018-07-25T23:22:43.986144Z 7 Query SHOW TRIGGERS LIKE 'time\_zone'
2018-07-25T23:22:43.986510Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.986590Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.986671Z 7 Query show table status like 'time\_zone\_leap\_second'
2018-07-25T23:22:43.987048Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.987127Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.987203Z 7 Query show create table `time_zone_leap_second`
2018-07-25T23:22:43.987304Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.987391Z 7 Query show fields from `time_zone_leap_second`
2018-07-25T23:22:43.987701Z 7 Query show fields from `time_zone_leap_second`
2018-07-25T23:22:43.988083Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `time_zone_leap_second`
2018-07-25T23:22:43.988272Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.988350Z 7 Query use `mysql`
2018-07-25T23:22:43.988428Z 7 Query select @@collation_database
2018-07-25T23:22:43.988520Z 7 Query SHOW TRIGGERS LIKE 'time\_zone\_leap\_second'
2018-07-25T23:22:43.988927Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.989012Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.989093Z 7 Query show table status like 'time\_zone\_name'
2018-07-25T23:22:43.989426Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.989499Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.989576Z 7 Query show create table `time_zone_name`
2018-07-25T23:22:43.989676Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.989762Z 7 Query show fields from `time_zone_name`
2018-07-25T23:22:43.990118Z 7 Query show fields from `time_zone_name`
2018-07-25T23:22:43.990513Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `time_zone_name`
2018-07-25T23:22:43.990668Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.990780Z 7 Query use `mysql`
2018-07-25T23:22:43.990899Z 7 Query select @@collation_database
2018-07-25T23:22:43.990991Z 7 Query SHOW TRIGGERS LIKE 'time\_zone\_name'
2018-07-25T23:22:43.991366Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.991446Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.991528Z 7 Query show table status like 'time\_zone\_transition'
2018-07-25T23:22:43.991905Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.991985Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.992062Z 7 Query show create table `time_zone_transition`
2018-07-25T23:22:43.992166Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.992254Z 7 Query show fields from `time_zone_transition`
2018-07-25T23:22:43.992573Z 7 Query show fields from `time_zone_transition`
2018-07-25T23:22:43.992929Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `time_zone_transition`
2018-07-25T23:22:43.993094Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.993171Z 7 Query use `mysql`
2018-07-25T23:22:43.993250Z 7 Query select @@collation_database
2018-07-25T23:22:43.993339Z 7 Query SHOW TRIGGERS LIKE 'time\_zone\_transition'
2018-07-25T23:22:43.993700Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.993779Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.993921Z 7 Query show table status like 'time\_zone\_transition\_type'
2018-07-25T23:22:43.994261Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.994335Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.994411Z 7 Query show create table `time_zone_transition_type`
2018-07-25T23:22:43.994518Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.994605Z 7 Query show fields from `time_zone_transition_type`
2018-07-25T23:22:43.995038Z 7 Query show fields from `time_zone_transition_type`
2018-07-25T23:22:43.995385Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `time_zone_transition_type`
2018-07-25T23:22:43.995541Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.995618Z 7 Query use `mysql`
2018-07-25T23:22:43.995697Z 7 Query select @@collation_database
2018-07-25T23:22:43.995788Z 7 Query SHOW TRIGGERS LIKE 'time\_zone\_transition\_type'
2018-07-25T23:22:43.996198Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.996283Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.996365Z 7 Query show table status like 'user'
2018-07-25T23:22:43.996842Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:43.996929Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.997007Z 7 Query show create table `user`
2018-07-25T23:22:43.997174Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.997266Z 7 Query show fields from `user`
2018-07-25T23:22:43.997933Z 7 Query show fields from `user`
2018-07-25T23:22:43.998546Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `user`
2018-07-25T23:22:43.998903Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:43.998988Z 7 Query use `mysql`
2018-07-25T23:22:43.999071Z 7 Query select @@collation_database
2018-07-25T23:22:43.999165Z 7 Query SHOW TRIGGERS LIKE 'user'
2018-07-25T23:22:43.999546Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:43.999626Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:43.999725Z 7 Query RELEASE SAVEPOINT sp
2018-07-25T23:22:43.999802Z 7 Query show table status like 'general\_log'
2018-07-25T23:22:44.000232Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:44.000307Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:44.000384Z 7 Query show create table `general_log`
2018-07-25T23:22:44.000484Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:44.000570Z 7 Query show fields from `general_log`
2018-07-25T23:22:44.000964Z 7 Query show fields from `general_log`
2018-07-25T23:22:44.001313Z 7 Query show table status like 'slow\_log'
2018-07-25T23:22:44.001748Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:44.001844Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:44.001923Z 7 Query show create table `slow_log`
2018-07-25T23:22:44.002027Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:44.002113Z 7 Query show fields from `slow_log`
2018-07-25T23:22:44.002492Z 7 Query show fields from `slow_log`
2018-07-25T23:22:44.002898Z 7 Init DB zhishuedu
2018-07-25T23:22:44.002971Z 7 Query SHOW CREATE DATABASE IF NOT EXISTS `zhishuedu`
2018-07-25T23:22:44.003052Z 7 Query SAVEPOINT sp
2018-07-25T23:22:44.003125Z 7 Query show tables
2018-07-25T23:22:44.003279Z 7 Query show table status like 'andyxi'
2018-07-25T23:22:44.003692Z 7 Query SET SQL_QUOTE_SHOW_CREATE=1
2018-07-25T23:22:44.003860Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:44.003945Z 7 Query show create table `andyxi`
2018-07-25T23:22:44.004048Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:44.004134Z 7 Query show fields from `andyxi`
2018-07-25T23:22:44.004451Z 7 Query show fields from `andyxi`
2018-07-25T23:22:44.004767Z 7 Query SELECT /*!40001 SQL_NO_CACHE */ * FROM `andyxi`
2018-07-25T23:22:44.005010Z 7 Query SET SESSION character_set_results = 'binary'
2018-07-25T23:22:44.005095Z 7 Query use `zhishuedu`
2018-07-25T23:22:44.005177Z 7 Query select @@collation_database
2018-07-25T23:22:44.005269Z 7 Query SHOW TRIGGERS LIKE 'andyxi'
2018-07-25T23:22:44.005600Z 7 Query SET SESSION character_set_results = 'utf8'
2018-07-25T23:22:44.005680Z 7 Query ROLLBACK TO SAVEPOINT sp
2018-07-25T23:22:44.005753Z 7 Query RELEASE SAVEPOINT sp

最后释放还原点。确认每个库中的每个表都备份完成后。才会执行这一步。

前面通过START TRANSACTION /*!40100 WITH CONSISTENT SNAPSHOT */ 开启的事务只能通过commit或者 rollback 来结束。而不是ROLLBACK TO SAVEPOINT sp
其实,这样做不会阻塞在备份期间对已经备份表的 ddl 操作。


2018-07-25T23:22:44.009873Z 7 Quit

mysqldump 备份过程可以描述为:
(1) 先发出一条 flush tables 关闭实例上所有打开的表
(2) 创建一个全局锁,FLUSH TABLES WITH READ LOCK获得 db 一致性状态。
(3) 设置事务隔离级别为 RR ,确保备份事务中任何时刻的数据都相同。
(4) 创建一个 RR 级别的事务一致性快照 ,执行START TRANSACTION /*!40100 WITH CONSISTENT SNAPSHOT */
(5) 根据参数--master-data=2 打印 SHOW MASTER STATUS 获取文件名和位置点信息。
(6) 执行UNLOCK TABLES 释放锁。
(7) 在开始做所有的事情之前创建了一个事务的还原点,然后先备份一张表,然后再回到事务的还原点,再继续备份下一张表,一直这样重复直到所有的表备份完成。最后把事务还原点释放掉。然后把这个事务 rollback 掉就可以了。

猜你喜欢

转载自www.cnblogs.com/chinaops/p/9369794.html