Home  >  Article  >  Database  >  MySQL控制台更新数据乱码解决_MySQL

MySQL控制台更新数据乱码解决_MySQL

WBOY
WBOYOriginal
2016-06-01 13:32:181124browse

bitsCN.com

MySQL控制台更新数据乱码解决

 

问题:

在MySQL控制台中输入如下语句:

 

INSERT INTO table_name VALUES ('中文');

 

最终在数据库存放的数据为乱码。

 

解决:

添加mysql客户端连接的字符集参数。(下面我们假设数据库的编码为utf-8)

 

1. 在控制台启动命令之后添加字符集参数

 

1$ mysql --default-character-set=utf8

 

 

注意,这边的的字符集是utf8而不是utf-8。

 

2. 在mysql的配置文件my.cnf中添加字符集参数

 

在/etc/my.cnf文件中添加如下配置

 

1[mysql]2default-character-set=utf8

 

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn