修改数据库字符集 旧表字符集不变
alter database owl default character set utf8;
修改表字符集
alter table t_app character set utf8;
转换表所有列字符集和默认字符集
alter table t_app convert to character set utf8;
修改单个字段字符集 注意有没有备注
alter table t_user change nick_name nick_name VARCHAR(35) character set utf8mb4 COLLATE utf8mb4_general_ci comment '订单号';
修改表名 重命名
alter table old_name rename new_name;
rename table old_name to new_name;
添加列 在t_user表添加列oid
alter table t_user add column oid varchar(10);
删除列
alter table t_user drop column oid;
修改列名 可同时修改列名和列类型
alter table t_user change column old_name new_name varchar(20);
修改列类型 把t_user表的owl_id列类型改为 varchar(20)
alter table t_user modify owl_id varchar(20);
从information_schema查所有列字符集
select table_schema,table_name,table_type,engine,table_rows,table_collation from tables;
查看系统字符集
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
查看表字符集
SHOW TABLE STATUS FROM owl WHERE NAME='t_user_oper_log';
show create table t_user_oper_log;
查看有所字段字符集
show full columns from t_app;
查看数据库所有表引擎
show table status from owl;
显示单个表存储引擎
show create table t_user_oper_log;
show table status from owl where name='t_user_oper_log'\G;
修改表引擎
alter table t_user_oper_log engine=myisam;