版本:
mysql> show variables like 'ver%';
+-------------------------+---------------------+
| Variable_name | Value |
+-------------------------+---------------------+
| version | 5.7.29-debug |
| version_comment | Source distribution |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
+-------------------------+---------------------+
4 rows in set (0.00 sec)
表结构:
mysql> show create table ddlutf8\G
*************************** 1. row ***************************
Table: ddlutf8
Create Table: CREATE TABLE `ddlutf8` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(300) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `i_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=655351 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> show create table ddltab_bak\G
*************************** 1. row ***************************
Table: ddltab_bak
Create Table: CREATE TABLE `ddltab_bak` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(300) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=393198 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysqld相关参数:
mysql> show global variables like '%online%';
+----------------------------------+---------+
| Variable_name | Value |
+----------------------------------+---------+
| innodb_online_alter_log_max_size | 8388608 |
+----------------------------------+---------+
1 row in set (0.00 sec)
mysql> show global variables like 'innodb_sort%';
+-------------------------+---------+
| Variable_name | Value |
+-------------------------+---------+
| innodb_sort_buffer_size | 1048576 |
+-------------------------+---------+
1 row in set (0.01 sec)
测试表的数据准备:
mysql> truncate table ddlutf8;
Query OK, 0 rows affected (0.71 sec)
mysql> insert into ddlutf8(name) select name from ddltab_bak;
Query OK, 262144 rows affected (42.12 sec)
Records: 262144 Duplicates: 0 Warnings: 0
实验开始。
会话一:
mysql> alter table ddlutf8 add coladded varchar(100);
迅速在另一窗口的会话二中执行:
mysql> insert into ddlutf8(name) select name from ddltab_bak;
不久,会话一alter失败,报错:
mysql> alter table ddlutf8 add coladded varchar(100);
ERROR 1799 (HY000): Creating index 'PRIMARY' required more than 'innodb_online_alter_log_max_size' bytes of modification log. Please try again.
会话二的insert会执行成功。