您的位置:首页 > 数据库 > MySQL

MySQL 字符集设置

2016-09-24 09:55 323 查看
/***************************************************************************
*                         MySQL 字符集设置
* 说明:
*     数据库这块很多时候都会因为字符集不兼容导致数据通信异常,所以这边把
* MySQL的字符集设定为utf-8,这个比较通用。
*
*                                         2016-9-24 深圳 南山平山村 曾剑锋
**************************************************************************/

一、参考文档:
1. (原创)Linux下MySQL 5.5/5.6的修改字符集编码为UTF8(彻底解决中文乱码问题) http://www.ha97.com/5359.html 
二、解决办法:
cat /etc/my.cnf
......
[client]
......
default-character-set=utf8
......
[mysql]
......
default-character-set=utf8
......
[mysqld]
......
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
......

三、查看结果:
[aplex@root ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73-log Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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> quit
Bye
[aplex@root ~]#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: