# centos mysql修改默认字符集为utf8mb4

**URL:** <https://www.shiqidu.com/t/topic/366>\
**Category:** 开发调优\
**Tags:** MySQL\
**Created:** [January 24, 2018, 6:39am UTC](https://www.shiqidu.com/t/topic/366 "2018-01-24T06:39:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
**Post date:** [January 24, 2018, 6:39am UTC](https://www.shiqidu.com/t/topic/366/1 "2018-01-24T06:39:33Z")

</div>

打开my.cnf，一般情况下载`etc`目录下

```bash
vi /etc/my.cnf    

```

然后修改内容(只列出需要修改的地方)

[mysqld]的修改如下

```bash
[mysqld]    
character-set-server = utf8mb4    
collation-server = utf8mb4_unicode_ci    

```

[client]的修改如下

```bash
[client]    
default-character-set = utf8mb4    

```

[mysql]的修改如下

```bash
[mysql]    
default-character-set = utf8mb4    

```

然后保存退出、重启mysqld服务。

```bash
systemctl restart mysqld    

```

然后查看字符集编码

```bash
SHOW VARIABLES LIKE 'character%';    

```
