# MySQL解决不支持中文的问题

> 来源：梦飞idc云平台 | 原文：https://www.mfisp.com/8559.html | 发布：2022-07-25 | 更新：2022-07-25 | 分类：IDC云库

### 前提

 

环境是ubuntu 下一个

 

### 方法

 

1.检查一下。mysql 默认字符集

 

![MySQL解决不支持中文的问题](https://www.mfisp.com/wp-content/uploads/2022/07/8559-MzjSEu.png)

 
 
- character_set_client 客户端代码； 
- character_set_connection 用于建立连接的代码； 
- character_set_database 数据库编码； 
- character_set_results 结果集的编码； 
- character_set_server 数据库服务器代码； 

 

2.修改配置文件

 

linux系统下，修改MySQL数据库默认编码的步骤为：

 
 
- 修改`/etc/mysql/mysql.conf.d/mysqld.cnf` 文件 

 

```
xhost +    # If xhost + Cannot perform , Report errors ：xhost ：  unable to open display “”
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
```

 
 
- 在[mysqld]下面添加 

 

```
# I'll change it to utf8mb4 It's because of storage emoji Expression error .

character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
```

 

![MySQL解决不支持中文的问题](https://www.mfisp.com/wp-content/uploads/2022/07/8559-9tyGYv.png)

 
 
- 修改mysql.cnf文件 

 

```
sudo gedit /etc/mysql/conf.d/mysql.cnf
```

 
 
- 在【mysql】下面添加 

 

```
default-character-set = utf8mb4
```

 

![MySQL解决不支持中文的问题](https://www.mfisp.com/wp-content/uploads/2022/07/8559-BLM6yG.png)

 

**3.重启mysql**

 

```
sudo service mysql stop
sudo service mysql start
```

 

**4.查看修改后的编码方式**

 

![MySQL解决不支持中文的问题](https://www.mfisp.com/wp-content/uploads/2022/07/8559-ly0iLs.png)

 

好了，设置完成，可以愉快的存储数据了，可以保存emoji表情了。

 

### 跟进

 

如果是现有表，可以先查看该表支持的字符集

 

```
show create table entries2;
```

 

然后根据情况修改表格的字符

 

```
alter table table_name convert to character set utf8mb4;
```

---
本页由 梦飞idc云平台（https://www.mfisp.com）提供。站点导航见 https://www.mfisp.com/llms.txt
