国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > 文庫 > 正文

如何用pt-online-schema-change在線修改表字段長度

2024-09-07 22:12:32
字體:
供稿:網(wǎng)友
       pt-online-schema-change依賴條件:
       操作的表必須有主鍵,否則執(zhí)行會報(bào)錯
 
       實(shí)驗(yàn)如下:
MySQL [mysql]> create database chenfeng;
Query OK, 1 row affected (0.00 sec)
 
MySQL [mysql]> use chenfeng;
Database changed
 
      創(chuàng)建帶有主鍵的表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)即為我們想要的結(jié)果。

(編輯:武林網(wǎng))

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 固阳县| 青州市| 六枝特区| 沂源县| 内江市| 建德市| 八宿县| 盘锦市| 峡江县| 沁源县| 伽师县| 长葛市| 天祝| 墨脱县| 延津县| 侯马市| 裕民县| 陆川县| 桑植县| 合肥市| 正镶白旗| 凤冈县| 石家庄市| 巫山县| 定边县| 军事| 洪雅县| 股票| 关岭| 陈巴尔虎旗| 通辽市| 安塞县| 达拉特旗| 徐州市| 星座| 浙江省| 襄城县| 大姚县| 云林县| 临澧县| 巴青县|