mysql的默认编码方式并不适合中文的显示,所以我们需要把mysql的默认编码模式修改一下。可以通过以下命令查看目前mysql的编码情况

show variables like "character%";

修改/etc/my.cnf 文件,添加或修改以下内容

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8  

或者使用utf8mb4编码

[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4

弄完后,记得重启mysql才会生效,效果如下

MariaDB [(none)]> show variables like "character%";
+--------------------------+------------------------------+
| Variable_name            | Value                        |
+--------------------------+------------------------------+
| character_set_client     | utf8                         |
| character_set_connection | utf8                         |
| character_set_database   | utf8                         |
| character_set_filesystem | binary                       |
| character_set_results    | utf8                         |
| character_set_server     | utf8                         |
| character_set_system     | utf8                         |
| character_sets_dir       | /usr/share/mariadb/charsets/ |
+--------------------------+------------------------------+

 

By charlie

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注