mysql表索引类型修改_MySQL 添加索引和字段,修改数据类型

MySQL 添加索引和字段,修改数据类型

1、添加索引的时候在会话级别关闭写入binlog功能,就不会传到从库,其它从库分别执行,执行完毕检测所有从库执行完成。

例如:

set session sql_log_bin=off;

alter table BI_AppointmentOrder_Cyh  add index idx_IdNo (IdNo);

2、添加字段,如果表小,低于5万多条,可以直接主库上执行alter,一定不能使用关闭binlog功能(set session sql_log_bin=off;)。

使用pt-online-schema-change工具添加

pt-online-schema-change --user=root --password=密码  -P3306 --critical-load="Threads_running=500" --no-drop-old-table  --alter "add column name varchar(32)"  --charset=utf8  D=库名,t=表名  --print  --dry-run

pt-online-schema-change --user=root --password=密码  -P3306 --critical-load="Threads_running=500" --no-drop-old-table  --alter "add column name varchar(32)"  --charset=utf8  D=库名,t=表名  --print  –execute

3、 修改数据类型,根据5.7官方文档介绍使用onlineDDL,小表直接在主库执行。大表用pt-online-schema-change工具添加。

例如:

pt-online-schema-change --user=root  -pxxxxx  -hlocalhost    --critical-load="Threads_running=500"   --no-drop-old-table   --alter " change column StartDate StartDate datetime  DEFAULT NULL COMMENT '开始时间'"   --charset=utf8  D=hp_cougar_transfer,t=BT_DoctorStopSchedule --print --dry-run

pt-online-schema-change --user=root  -pxxxxx  -hlocalhost    --critical-load="Threads_running=500"   --no-drop-old-table   --alter " change column StartDate StartDate datetime  DEFAULT NULL COMMENT '开始时间'"   --charset=utf8  D=hp_cougar_transfer,t=BT_DoctorStopSchedule --print –execute

注意:pt-online-schema-change执行后会保留旧表_开头,建议保留3个月。

4、创建表,一定要检测字符集、引擎和主键。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值