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

CentOS查看和修改MySQL字符集

时间:2014-12-30 17:21:22      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:修改mysql字符集

通过以下命令查看了MySQL的字符集

连接上mysql服务,输入以下命令

mysql>show variables like ‘character_set%‘;

显示如下:

[plain] view plaincopy

+--------------------------+----------------------------+  

| 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/ |  

+--------------------------+----------------------------+  


为了让MySQL支持中文,需要把字符集改变成UTF8,

方法如下:

1. 打开etc/my.cnf

2. 修改成如下内容,保存

[plain] view plaincopy

[client]  

port=3306  

socket=/var/lib/mysql/mysql.sock  

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  

character-set-server=utf8  

  

[mysql]  

no-auto-rehash  

default-character-set=utf8  

  

[mysqld_safe]  

log-error=/var/log/mysqld.log  

pid-file=/var/run/mysqld/mysqld.pid  


3. 重启mysql服务:service mysqld restart

再次查看mysql编码,已经更新成如下信息

[plain] view plaincopy

+--------------------------+----------------------------+  

| 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/ |  

+--------------------------+----------------------------+  


本文出自 “网络工程专题” 博客,请务必保留此出处http://houzhibo.blog.51cto.com/3103241/1597812

CentOS查看和修改MySQL字符集

标签:修改mysql字符集

原文地址:http://houzhibo.blog.51cto.com/3103241/1597812

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