Environment:
All character sets for project DB have been initialized to Utf-8, as shown in the status command:
Server Characterset:utf8
Db Characterset:utf8
Client Characterset:utf8
Conn. Characterset:utf8
First, modify the corresponding project database level character set:
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)
Second, modify the table-level character set:
ALTER TABLE T1 CHARSET=UTF8MB4;
Third, modify the configuration of the Client connection database:
return [
' Class ' = ' yii\db\connection ',
' drivername ' = ' mysql ',
' DSN ' = ' mysql:host=xxxx;port=3306;dbname=yyf; ',
' Username ' = ' xxxx ',
' Password ' = ' xxxx ',
# # # ' charset ' = ' utf8 ',' charset ' = ' utf8mb4 ',
];
Modify the encoding to UTF8MB4 to support emoji emoticons