🌞

Ubuntu MySQL 5.7 修改字符编码为UTF8

至今不清楚为什么MySQL默认编码方式不是utf8,没办法,每次安装完MySQL之后必不可少的一步就是修改默认编码方式。

  1. 修改/etc/mysql/my.cnf文件,添加如下三行:
[client]
default-character-set=utf8

[mysqld]
character-set-server=utf8

[mysql]
default-character-set=utf8
  1. 重启mysql服务即可:
1
service mysql restart

此时,查看mysql默认编码:

mysql> 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/mysql/charsets/ |
+--------------------------+----------------------------+
updatedupdated2020-01-122020-01-12
加载评论