mysql 5.5 mysqldump备份原理

Posted hufangrui

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 5.5 mysqldump备份原理相关的知识,希望对你有一定的参考价值。

开启general_log日志,获取mysqldump执行语句

show VARIABLES like ‘general_log%‘
set GLOBAL general_log=on

执行备份命令

mysqldump --single-transaction -uroot -pdmysqlbadmin --master-data=2 -A  -R -E >/data/test.sql
得到general_log日志
161109 14:48:25	    8 Connect	[email protected] on 
		    8 Query	/*!40100 SET @@SQL_MODE=‘‘ */
		    8 Query	/*!40103 SET TIME_ZONE=‘+00:00‘ */
		    8 Query	FLUSH /*!40101 LOCAL */ TABLES
		    8 Query	FLUSH TABLES WITH READ LOCK
		    8 Query	SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ
		    8 Query	START TRANSACTION /*!40100 WITH CONSISTENT SNAPSHOT */
		    8 Query	SHOW MASTER STATUS
		    8 Query	UNLOCK TABLES
		    8 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 GROUP BY LOGFILE_GROUP_NAME, FILE_NAME, ENGINE ORDER BY LOGFILE_GROUP_NAME
		    8 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
		    8 Query	SHOW DATABASES
		    8 Init DB	accesslog
		    8 Query	SHOW CREATE DATABASE IF NOT EXISTS `accesslog`
		    8 Query	show tables
		    8 Query	show table status like ‘accesslog‘
		    8 Query	SET OPTION SQL_QUOTE_SHOW_CREATE=1
		    8 Query	SET SESSION character_set_results = ‘binary‘
		    8 Query	show create table `accesslog`
		    8 Query	SET SESSION character_set_results = ‘utf8‘
		    8 Query	show fields from `accesslog`
		    8 Query	SELECT /*!40001 SQL_NO_CACHE */ * FROM `accesslog`
		    8 Query	SET SESSION character_set_results = ‘binary‘
		    8 Query	use `accesslog`
		    8 Query	select @@collation_database
		    8 Query	SHOW TRIGGERS LIKE ‘accesslog‘		   
		    8 Query	SET SESSION character_set_results = ‘utf8‘
		    8 Query	show events
		    8 Query	use `accesslog`
		    8 Query	select @@collation_database
		    8 Query	SET SESSION character_set_results = ‘binary‘
		    8 Query	SHOW CREATE EVENT `E_delAccessLog`
		    8 Query	SET SESSION character_set_results = ‘utf8‘
		    8 Query	use `accesslog`
		    8 Query	select @@collation_database
		    8 Query	SET SESSION character_set_results = ‘binary‘
		    8 Query	SHOW FUNCTION STATUS WHERE Db = ‘accesslog‘
		    8 Query	SHOW PROCEDURE STATUS WHERE Db = ‘accesslog‘
		    8 Query	SHOW CREATE PROCEDURE `P_delAccessLog`
		    8 Query	SET SESSION character_set_results = ‘utf8‘

 测试方法,这里就不贴了,总结

1、非事务引擎表,有数据不一致风险,例如:myisam。
2、执行备份过程中,不允许有create table 及create database操作,事务里无法控制该类型语句,导致不一致备份。
3、如果之前有使用osc在线修改表结构,等它执行完后,再做备份。

 


以上是关于mysql 5.5 mysqldump备份原理的主要内容,如果未能解决你的问题,请参考以下文章

MySQL探测mysqldump详细过程

MySQL Backup mysqldump备份流程学习

MySQL Backup mysqldump备份流程学习

MySQL备份--xtrabackup与mysqldump工具使用

将MySQL 5.1升级到MySQL 5.5的步骤

mysqldump和xtrabackup备份原理实现说明