时间:2021-07-01 10:21:17 帮助过:2人阅读
创建和修改数据库字符集:
create database mydb character set utf8 collate utf8_general_ci; alter database mini default character set = gb2312;
修改数据表字符集:
alter table pub_logs default character set = gb2312; alter table pub_logs convert to character set gb2312;
生成批量修改表字符集:
SELECT a.TABLE_TYPE,CONCAT(‘alter TABLE ‘,A.TABLE_NAME,‘ default character set = gb2312;‘) FROM INFORMATION_SCHEMA.TABLES A WHERE A.TABLE_SCHEMA=‘MINI‘ AND a.TABLE_TYPE=‘BASE TABLE‘
生成批量修改列字符集:
SELECT CONCAT(CONCAT(CONCAT(‘alter TABLE ‘,c.TABLE_NAME,‘ modify‘),CONCAT(‘ ‘,C.COLUMN_NAME,‘ ‘),C.COLUMN_TYPE),‘ ‘,‘ character set gb2312 COLLATE gb2312_chinese_ci;‘) AS CLOU
FROM
INFORMATION_SCHEMA.COLUMNS C,INFORMATION_SCHEMA.TABLES A
WHERE c.TABLE_SCHEMA=‘MINI‘
AND A.TABLE_NAME=c.TABLE_NAME
AND A.TABLE_TYPE=‘BASE TABLE‘
AND c.DATA_TYPE=‘varchar‘
;
mysql常用的一些命令,用于查看数据库、表、字段编码
标签: