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

MySQL字符集的设置

时间:2015-03-14 06:21:30      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:mysql字符集

  1. 查看MySQL数据库当前设置的字符集

mysql> SHOW VARIABLES LIKE ‘character%‘;
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | latin1                     |
| character_set_connection | latin1                     |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | latin1                     |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

2.临时更改MySQL数据库的字符集

mysql> SET character_set_client = utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> SET character_set_connection = utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> SET character_set_results = utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> SET character_set_server = utf8;
Query OK, 0 rows affected (0.00 sec)

 

3.查看数据库字符集是否更改成功

mysql> 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         | utf8                                        |
| character_set_system       | utf8                                        |
| character_sets_dir             | /usr/share/mysql/charsets/     |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

4.重启mysql服务器

[root@localhost ~]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                             [  OK  ]

5.查看MySQL字符集

 

mysql> SHOW VARIABLES LIKE ‘character%‘;
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | latin1                     |
| character_set_connection | latin1                     |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | latin1                     |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

6.永久修改MySQL字符集

[root@localhost ~]# vim  /etc/my.cnf
[mysqld]
..............
default-character-set=utf8

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

7.重新启动MySQL数据库

[root@localhost ~]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                            [  OK  ]

 

7.再次查看MySQL字符集设置是否生效

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)

本文出自 “云人生” 博客,请务必保留此出处http://ovcer.blog.51cto.com/1145188/1620196

MySQL字符集的设置

标签:mysql字符集

原文地址:http://ovcer.blog.51cto.com/1145188/1620196

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