pt-online-schema-change 使用基础4

2022-05-03 11:58:00 浏览数 (1)

至少需要一个主键或唯一索引

Note: In almost all cases a PRIMARY KEY or UNIQUE INDEX needs to be present in the table. This is necessary because the tool creates a DELETE trigger to keep the new table updated while the process is running.

添加主键

代码语言:javascript复制
mysql> show create table forpttestG
*************************** 1. row ***************************
       Table: forpttest
Create Table: CREATE TABLE `forpttest` (
  `id` int(6) DEFAULT NULL,
  `name` char(10) DEFAULT NULL,
  `comment` char(10) DEFAULT NULL,
  `abc` char(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

mysql> alter table `forpttest` add primary key (`id`);
Query OK, 0 rows affected (0.09 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show create table forpttestG
*************************** 1. row ***************************
       Table: forpttest
Create Table: CREATE TABLE `forpttest` (
  `id` int(6) NOT NULL DEFAULT '0',
  `name` char(10) DEFAULT NULL,
  `comment` char(10) DEFAULT NULL,
  `abc` char(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

mysql> 
mysql> desc forpttest;
 --------- ---------- ------ ----- --------- ------- 
| Field   | Type     | Null | Key | Default | Extra |
 --------- ---------- ------ ----- --------- ------- 
| id      | int(6)   | NO   | PRI | 0       |       |
| name    | char(10) | YES  |     | NULL    |       |
| comment | char(10) | YES  |     | NULL    |       |
| abc     | char(10) | YES  |     | NULL    |       |
 --------- ---------- ------ ----- --------- ------- 
4 rows in set (0.00 sec)

mysql>

0 人点赞