内容简介:Linux下MySQL_5.5的修改字符集编码为UTF8
背景
mysql安装后, 插入的数据位乱码, 经检查为默认字符集是 latin1
, 而程序使用 UTF-8
.
检查字符集
1.使用ssh终端连接mysql
mysql -h 127.0.0.1 -u root -p
2.查看字符集
show variables like 'character%';
显示如下
+--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+
character_set_database和character_set_server的默认字符集还是latin1.
解决方案
修改 mysql 的 my.cnf
文件中的字符集键值, my.cnf
一般位于 /etc
目录下, 没找到的话可以使用 find / -name my.cnf
查找.
1.在[client]字段里加入default-character-set=utf8
[client] port = 3306 socket = /var/lib/mysql/mysql.sock default-character-set=utf8
2.在[mysqld]字段里加入character-set-server=utf8
[mysqld] port = 3306 socket = /var/lib/mysql/mysql.sock character-set-server=utf8
3.在[mysql]字段里加入default-character-set=utf8
[mysql] no-auto-rehash default-character-set=utf8
修改完成后,service mysql restart重启mysql服务就生效.
注意: [mysqld]字段与[mysql]字段是有区别的.
4.再次查看字符集
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/ | +--------------------------+----------------------------+
5.如果上面的都修改了还乱码,那剩下问题就一定在connection连接层上.
SET NAMES 'utf8';
该语句相当于
SET character_set_client = utf8; SET character_set_results = utf8; SET character_set_connection = utf8;
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- oracle查看字符集 修改字符集
- Oracle 字符集实验
- go基础库之解码非Unicode字符集中的字符串
- [MySQL]支持 emoji(字符集问题)
- 带你5分钟读懂MySQL字符集设置
- Docker下mysql设置字符集的方法
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Building Web Reputation Systems
Randy Farmer、Bryce Glass / Yahoo Press / 2010 / GBP 31.99
What do Amazon's product reviews, eBay's feedback score system, Slashdot's Karma System, and Xbox Live's Achievements have in common? They're all examples of successful reputation systems that enable ......一起来看看 《Building Web Reputation Systems》 这本书的介绍吧!