如何用pt-online-schema-change在线修改表字段长度
发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,pt-online-schema-change依赖条件:操作的表必须有主键,否则执行会报错实验如下:MySQL [mysql]> create database chenfeng;Query OK,
千家信息网最后更新 2025年02月02日如何用pt-online-schema-change在线修改表字段长度pt-online-schema-change依赖条件:
操作的表必须有主键,否则执行会报错
实验如下:
MySQL [mysql]> create database chenfeng;
Query OK, 1 row affected (0.00 sec)
MySQL [mysql]> use chenfeng;
Database changed
创建带有主键的表test:
MySQL [chenfeng]> create table test
-> (id int(10) not null auto_increment,
-> k int(10) not null default '0',
-> c char(120) not null default '',
-> primary key(id))
-> engine=innodb default charset=utf8;
Query OK, 0 rows affected (0.03 sec)
MySQL [chenfeng]> desc test;
+-------+-----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| k | int(10) | NO | | 0 | |
| c | char(120) | NO | | | |
+-------+-----------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
MySQL [chenfeng]>
MySQL [chenfeng]> show create table test\G
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`k` int(10) NOT NULL DEFAULT '0',
`c` char(120) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
[root@chenfeng ~]# pt-online-schema-change --alter="modify c varchar(150) not null default ''" --user=root --password=123456 D=chenfeng,t=test --charset=utf8 --execute
No slaves found. See --recursion-method if host chenfeng has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
analyze_table, 10, 1
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
Altering `chenfeng`.`test`...
Creating new table...
Created new table chenfeng._test_new OK.
Altering new table...
Altered `chenfeng`.`_test_new` OK.
2016-10-07T18:57:36 Creating triggers...
2016-10-07T18:57:36 Created triggers OK.
2016-10-07T18:57:36 Copying approximately 1 rows...
2016-10-07T18:57:36 Copied rows OK.
2016-10-07T18:57:36 Analyzing new table...
2016-10-07T18:57:36 Swapping tables...
2016-10-07T18:57:36 Swapped original and new tables OK.
2016-10-07T18:57:36 Dropping old table...
2016-10-07T18:57:36 Dropped old table `chenfeng`.`_test_old` OK.
2016-10-07T18:57:36 Dropping triggers...
2016-10-07T18:57:36 Dropped triggers OK.
Successfully altered `chenfeng`.`test`.
[root@chenfeng ~]#
MySQL [(none)]> use chenfeng
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [chenfeng]> show tables;
+-----------------+
| Tables_in_chenfeng |
+-----------------+
| test |
+-----------------+
1 row in set (0.00 sec)
MySQL [chenfeng]> desc test;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| k | int(10) | NO | | 0 | |
| c | varchar(150) | NO | | | |
+-------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
varchar(150)即为我们想要的结果。
操作的表必须有主键,否则执行会报错
实验如下:
MySQL [mysql]> create database chenfeng;
Query OK, 1 row affected (0.00 sec)
MySQL [mysql]> use chenfeng;
Database changed
创建带有主键的表test:
MySQL [chenfeng]> create table test
-> (id int(10) not null auto_increment,
-> k int(10) not null default '0',
-> c char(120) not null default '',
-> primary key(id))
-> engine=innodb default charset=utf8;
Query OK, 0 rows affected (0.03 sec)
MySQL [chenfeng]> desc test;
+-------+-----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| k | int(10) | NO | | 0 | |
| c | char(120) | NO | | | |
+-------+-----------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
MySQL [chenfeng]>
MySQL [chenfeng]> show create table test\G
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`k` int(10) NOT NULL DEFAULT '0',
`c` char(120) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
[root@chenfeng ~]# pt-online-schema-change --alter="modify c varchar(150) not null default ''" --user=root --password=123456 D=chenfeng,t=test --charset=utf8 --execute
No slaves found. See --recursion-method if host chenfeng has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
analyze_table, 10, 1
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
Altering `chenfeng`.`test`...
Creating new table...
Created new table chenfeng._test_new OK.
Altering new table...
Altered `chenfeng`.`_test_new` OK.
2016-10-07T18:57:36 Creating triggers...
2016-10-07T18:57:36 Created triggers OK.
2016-10-07T18:57:36 Copying approximately 1 rows...
2016-10-07T18:57:36 Copied rows OK.
2016-10-07T18:57:36 Analyzing new table...
2016-10-07T18:57:36 Swapping tables...
2016-10-07T18:57:36 Swapped original and new tables OK.
2016-10-07T18:57:36 Dropping old table...
2016-10-07T18:57:36 Dropped old table `chenfeng`.`_test_old` OK.
2016-10-07T18:57:36 Dropping triggers...
2016-10-07T18:57:36 Dropped triggers OK.
Successfully altered `chenfeng`.`test`.
[root@chenfeng ~]#
MySQL [(none)]> use chenfeng
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [chenfeng]> show tables;
+-----------------+
| Tables_in_chenfeng |
+-----------------+
| test |
+-----------------+
1 row in set (0.00 sec)
MySQL [chenfeng]> desc test;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| k | int(10) | NO | | 0 | |
| c | varchar(150) | NO | | | |
+-------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
varchar(150)即为我们想要的结果。
条件
结果
会报
实验
字段
长度
在线
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
win10底层数据库
信息网络安全通报机制
数据库 数字转换成文本格式
海曙一站式软件开发外包
宿州映雪网络技术服务有限公司
互联网 下科技公司
宜章软件开发工程师学费多少
戴尔家用服务器远程管理
网管操作网络安全
gis许可服务器启动失败
炬成网络技术有限公司
网络安全周练习题
怎么查看电脑数据库文件
虚拟网络技术在局域网中的应用
阳江民宿软件开发
如何在国泰安数据库上下载数据
手机打鱼游戏软件开发
app软件开发技术路线
数据库查询姓名中包含某字的姓名
长沙全速网络技术有限公司校招
工行软件开发中心笔试难不难
高校买的数据库怎么用
哈皮服务器
服务器mc赚钱
中华民族网络安全时间
营造活动期间的网络安全环境
国内服务器维护费用
拼接宏基因组服务器配置
源码编辑器怎么做多人服务器
数据库查表内某一列