linux mysql 设置编码

首先查找MySql的cnf文件的位置:

[root@bdpp10 sfapp]#  find / -iname '*.cnf' -print
/etc/myback.cnf
/etc/pki/tls/openssl.cnf
/etc/my.cnf
/usr/share/mysql/my-innodb-heavy-4G.cnf
/usr/share/mysql/my-medium.cnf
/usr/share/mysql/my-large.cnf
/usr/share/mysql/my-small.cnf
/usr/share/mysql/my-huge.cnf
/usr/share/doc/mysql-server-5.1.73/my-innodb-heavy-4G.cnf
/usr/share/doc/mysql-server-5.1.73/my-medium.cnf
/usr/share/doc/mysql-server-5.1.73/my-large.cnf
/usr/share/doc/mysql-server-5.1.73/my-small.cnf
/usr/share/doc/mysql-server-5.1.73/my-huge.cnf
[root@bdpp10 sfapp]# 

 

然后拷贝my-medium.cnf 到 /etc/my.cnf 下 ,如果/etc/my.cnf 已经存在,最好先备份好

mv /etc/my.cnf   /etc/myback.cnf


[root@flyHome gaoxiang]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf 

 

再修改my.cnf

[root@flyHome gaoxiang]# vi /etc/my.cnf

在[client]下添加

default-character-set=utf8


在[mysql]下添加

default-character-set=utf8


在[mysqld]下添加
collation_server = utf8_general_ci
character_set_server = utf8

保存退出后重启mysqld:

[root@flyHome gaoxiang]#service mysqld restart

 

完成以上的操作就OK了。

 

看一下效果:

mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| 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/ |


如果要修改已经建立的数据库的编码,可以执行下面的语句,比如数据库名称是hive

alter database hive CHARACTER SET utf8;

如果想查看你建的数据用的什么编码,可以在information_schema.information_schema这个表中查看

你可能感兴趣的:(linux)