Fork me on GitHub

Ubuntu MySQL 5.7 修改字符编码为UTF8

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

  1. 修改/etc/mysql/my.cnf文件,添加如下三行:

    1
    2
    3
    4
    5
    6
    7
    8
    [client]
    default-character-set=utf8
    [mysqld]
    character-set-server=utf8
    [mysql]
    default-character-set=utf8
  2. 重启mysql服务即可:

    1
    service mysql restart

此时,查看mysql默认编码:

1
2
3
4
5
6
7
8
9
10
11
12
13
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/ |
+--------------------------+----------------------------+

梦想还是要有的,万一有人赏了呢