AUTO_INCREMENT 自增id 改为 AUTO_RANDOM 报错


root@[test]>CREATE TABLE t100 (a BIGINT PRIMARY KEY CLUSTERED auto_increment, b VARCHAR(255));
Query OK, 0 rows affected (0.10 sec)

root@[test]>show create table t100\G
*************************** 1. row ***************************
       Table: t100
Create Table: CREATE TABLE `t100` (
  `a` bigint(20) NOT NULL AUTO_INCREMENT,
  `b` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.01 sec)

root@[test]>alter table t100 modify a  BIGINT AUTO_RANDOM;
ERROR 8200 (HY000): Unsupported modify column: can't remove auto_increment without @@tidb_allow_remove_auto_inc enabled
root@[test]>
root@[test]>show variables like 'tidb_allow_remove_auto_inc';
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| tidb_allow_remove_auto_inc | OFF   |
+----------------------------+-------+
1 row in set (0.01 sec)

root@[test]>set global tidb_allow_remove_auto_inc=on;
ERROR 1228 (HY000): Variable 'tidb_allow_remove_auto_inc' is a SESSION variable and can't be used with SET GLOBAL

root@[test]>set tidb_allow_remove_auto_inc=on;
Query OK, 0 rows affected (0.01 sec)

root@[test]>alter table t100 modify a  BIGINT AUTO_RANDOM;
Query OK, 0 rows affected (0.11 sec)

root@[test]>show create table t100\G
*************************** 1. row ***************************
       Table: t100
Create Table: CREATE TABLE `t100` (
  `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,
  `b` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_rand_base] AUTO_RANDOM_BASE=2 */
1 row in set (0.05 sec)