Part1:写在最前
在MysQL5.6版本中,可以把undo log 回滚日志分离到一个单独的表空间里;其缺点是不能回收空间大小,until MysQL5.7,but MariadDB10.1暂不支持。
本文介绍并演示MysQL5.7是如何在线收缩undo log的。
undo log日志是保存在共享表空间ibdata1文件中的,随着数据库的运行时间的不断增长,ibdata1文件会越来越大,在以往的MySQL数据库版本中,如果我们想要回收ibdata1文件所占空间,会非常的复杂和困难,必须先将mysqldump -A全库导出,然后删掉data目录,再重新对数据库进行初始化,最后导入全库备份,方可实现ibdata1的回收。
MySQL全库备份方式可参考:
MySQL5.7的安装方式可参考:
①首先我们需要调整my.cnf参数
Warning:警告
其中innodb_undo_directory参数要在数据库初始化时就需要写入my.cnf,否则会报如下错误:
Expected to open 4 undo tablespaces but was able to find only 0 undo tablespaces. Set the innodb_undo_tablespaces parameter to the correct value and retry. Suggested value is 0
Part2:MySQL5.7在线回收undolog
①首先对一张100万行的表进行整表更新
②注意undolog的日志大小
[root@HE3 undolog]# ls -lshrt
total 412M
128M -rw-r----- 1 mysql mysql 128M Sep 26 16:56 undo004
76M -rw-r----- 1 mysql mysql 76M Sep 26 16:56 undo003
136M -rw-r----- 1 mysql mysql 136M Sep 26 16:56 undo001
72M -rw-r----- 1 mysql mysql 72M Sep 26 16:56 undo002
③error.log日志