一、正式环境操作注意事项:1、关闭应用访问或者设置数据库只读mysql设为只读方法:开启只读:mysql> show global variables like "%read_only%"; #查看相关参数,OFF为关,ON为开,默认为OFFmysql> flush tables with read lock;mysql> set global read_only=1;关闭只读:mysql> unlock tables;mysql> set global read_only=0;mysql> show global variables like "%read_only%";2、操作前备份数据库3、开始及结束检查外键引用参数4、操作时间为晚间二、批量修改字段类型流程#未防止字段进行了外键关联,批量操作前临时关闭mysql外键引用,mysql内执行mysql> SET foreign_key_checks = 0; #获得修改语句并存储到临时表mysql> USE db;mysql> CREATE TEMPORARY TABLE XIUGAI SELECT CONCAT( 'alter table ',table_name,' MODIFY COLUMN ',column_name, ' datetime(3) ;' ) AS col FROM INFORMATION_SCHEMA.columns a WHERE TABLE_SCHEMA = 'ofbiz' AND data_type IN ('datetime') ;#查看获得的语句mysql> SELECT * FROM XIUGAI;#mysql外执行,导出表内容,-N不带列名 -e执行语句mysql -uroot -p -N -e "select * from XIUGAI" db>/home/abc/XIUGAI.SQL#mysql外执行,通过脚本批量执行alter语句mysql -uroot -p db SET foreign_key_checks = 1;#核对外键引用是否开启,mysql内执行,1代表开启,0代表关闭mysql> SELECT @@FOREIGN_KEY_CHECKS;