环境:
项目db的所有字符集都已经初始化为utf-8,如 status命令显示如下:
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
一、修改对应项目数据库级别字符集:
mysql> show create database yyf;
+----------+--------------------------------------------------------------+
| Database | Create Database |
+----------+--------------------------------------------------------------+
| yyf | CREATE DATABASE `yyf` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+--------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> alter database yyf CHARACTER SET utf8mb4;
Query OK, 1 row affected (0.00 sec)
mysql> show create database yyf;
+----------+-----------------------------------------------------------------+
| Database | Create Database |
+----------+-----------------------------------------------------------------+
| yyf | CREATE DATABASE `yyf` /*!40100 DEFAULT CHARACTER SET utf8mb4 */ |
+----------+-----------------------------------------------------------------+
1 row in set (0.00 sec)
二、修改表级别的字符集:
alter table t1 CHARSET=utf8mb4;
三、修改客户端连接数据库的配置:
'class' => 'yiidbConnection',
'driverName' => 'mysql',
'dsn' => 'mysql:host=xxxx;port=3306;dbname=yyf;',
'username' => 'xxxx',
'password' => 'xxxx',
###'charset' => 'utf8',
];