参考自:http://www.blogjava.net/xiaomage234/archive/2014/07/25/416200.html
案例1、在线DDL报错提示日志空间不足
MySQL 往一张大表添加字段时报如下错误:
ERROR 1799 (HY000) at line 1: Creating index 'PRIMARY' required more than 'innodb_online_alter_log_max_size' bytes of modification log. Please try again.
解决方法:
我的数据库为MySQL 5.5版本,innodb_online_alter_log_max_size值为默认大小128M。
mysql> show variables like 'innodb_online_alter_log_max_size';
+——————————————+———————-+
| Variable_name | Value |
+——————————————+———————-+
| innodb_online_alter_log_max_size | 134217728 |
+——————————————+———————-+
1 rows in set (0.00 sec)
该参数为动态参数且全局的,可通过如下命令加大
mysql> set global innodb_online_alter_log_max_size=402653184;
Query OK, 0 rows affected (0.03 sec)
加到合适大小,我往120G大小表里添加字段设置该值4G,成功执行。
案例2、事务日志文件设置太小:
MySQL日志:
140306 12:03:25 InnoDB: ERROR: the age of the last checkpoint is 9434024,
InnoDB: which exceeds the log group capacity 9433498.
InnoDB: If you are using big BLOB or TEXT rows, you must set the
InnoDB: combined size of log files at least 10 times bigger than the
InnoDB: largest such row.
应该是Innodb引擎下日志大小设置过小导致的,某个事物产生大量日志,但innodb_log_file_size设置过小,可以加大解决。
解决方法:
STEP 01) 修改配置文件 /etc/my.cnf
[mysqld]
innodb_log_buffer_size = 32M
innodb_buffer_pool_size = 3G
innodb_log_file_size = 768M
STEP 02) mysql -uroot -p -e"SET GLOBAL innodb_fast_shutdown = 0;" # 强制全部内容都执行刷脏到文件中,便于安全关闭数据库
STEP 03) service mysql stop
STEP 04) rm -f /var/lib/mysql/ib_logfile*
STEP 05) service mysql start
案例3、pt-osc加字段时候报错:
收到错误如下:
# pt-online-schema-change –alter="add column tag_common text default null" –user=root –password=xxxxxxxx D=MYDB,t=MYTB –execute
Cannot connect to D=lsedata_13Q1,h=10.13.7.47,p=…,u=root
No slaves found. See –recursion-method if host BJL1-Y13-10-ops.gaoder.net has slaves.
Not checking slave lag because no slaves were found and –check-slave-lag was not specified.
# A software update is available:
# * Percona Toolkit 2.2.6 has a possible security issue (CVE-2014-2029) upgrade is recommended. The current version for Percona::Toolkit is 2.2.7.
The table `MYDB`.`MYTB` has triggers. This tool needs to create its own triggers, so the table cannot already have triggers.
这是MYTB表上之前就有触发器的原因,可以从pt-online-schema-change的工作机制了解到:
1) 如果存在外键,根据alter-foreign-keys-method参数值,检测外键相关的表,针对相应的设置进行处理;
2) 创建一个新的表,表结构修改后的数据表,用于从源数据表向新表中导入数据;
3) 创建触发器,在复制数据开始之后,将对源数据表继续进行数据修改的操作记录下来,以便在数据复制结束后执行这些操作,保证数据不会丢失;
4) 复制数据,从源数据表中复制数据到新表中;
5) 修改外键相关的子表,根据修改后的数据,修改外键关联的子表;
6) 更改源数据表为old表,把新表更改为源表名,并将old表删除;
7) 删除触发器;