码迷,mamicode.com
首页 > 数据库 > 详细

MySQL设置各类字符集

时间:2019-06-26 19:14:34      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:nbsp   说明   rac   sock   star   system   index   问题   socket   

一、查看字符集编码:

登录mysql

show variables like ‘%character%‘;

 

二、修改编码:

编辑/etc/my.cnf ,设置后的配置文件如下:

[root@node03 /]# cat /etc/my.cnf
[mysql]
default-character-set=utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set=utf8
character_set_server=utf8
#lower_case_table_names=1 忽略大小写

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
default-character-set=utf8
[mysql.server]
default-character-set=utf8
[client]
default-character-set=utf8

 

三、重启MySQL服务:

service mysql restart

 

四、如果上面的都修改了还乱码,那剩下问题就一定在connection连接层上。解决方法是在发送查询前执行一下下面这句(直接写在SQL文件的最前面):

SET NAMES ‘utf8‘;

它相当于下面的三句指令:
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;

 

执行show variables like ‘character%‘ 跟下面一样说明修改成功

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

MySQL设置各类字符集

标签:nbsp   说明   rac   sock   star   system   index   问题   socket   

原文地址:https://www.cnblogs.com/mediocreWorld/p/11093191.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!