木林森2014

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

环境:

项目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;

 

三、修改客户端连接数据库的配置:

 return [
'class' => 'yii\db\Connection',
'driverName' => 'mysql',
'dsn' => 'mysql:host=xxxx;port=3306;dbname=yyf;',
'username' => 'xxxx',
'password' => 'xxxx',
###'charset' => 'utf8',
'charset' => 'utf8mb4',
];

 

posted on 2015-11-11 17:55  木林森2014  阅读(1067)  评论(0编辑  收藏  举报