修改MySQL数据库和表的字符集

2021-08-13  本文已影响0人  jackli0855

Convert the Collation of a Database

ALTER DATABASE DBNAME CHARACTER SET utf8 COLLATE utf8_general_ci;

注意: 把DBNAME替换成自己的数据库

Convert the Collation of all Tables

SELECT CONCAT("ALTER TABLE ", TABLE_SCHEMA, '.', TABLE_NAME,' COLLATE utf8_general_ci;')
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='DBNAME' AND TABLE_TYPE = 'BASE TABLE';

注意:

Convert the Collation of Table Columns

SELECT CONCAT('ALTER TABLE `', TABLE_NAME,'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;') AS    mySQL
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA= "DBNAME" AND TABLE_TYPE="BASE TABLE"

注意:

上一篇下一篇

猜你喜欢

热点阅读