Linux下mysql修改字符集

登录到 mysql

# mysql -uroot -p 

查看字符集

 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)

这里我已经修改好了 如果没修改过的话 utf8 应该有一些是 latin

首先查找 cnf 文件

find / -iname '*.cnf' -print
[root@localhost canal]# find / -iname '*.cnf' -print
/usr/share/mysql/my-medium.cnf
/usr/share/mysql/my-large.cnf
/usr/share/mysql/my-huge.cnf
/usr/share/mysql/my-small.cnf
/usr/share/mysql/my-innodb-heavy-4G.cnf
/usr/share/doc/kpathsea-2007/kpathsea_defaults/texmf-kpathsea-defaults.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-huge.cnf
/usr/share/doc/mysql-server-5.1.73/my-small.cnf
/usr/share/doc/mysql-server-5.1.73/my-innodb-heavy-4G.cnf
/etc/my.cnf
/etc/pki/tls/openssl.cnf

将 my-small.cnf、my-medium.cnf、my-huge.cnf、my-innodb-heavy-4G.cnf 其中一个到 /etc/my.cnf 下

cp /usr/share/mysql/my-medium.cnf /etc/my.cnf 

输入 y

vim /etc/my.cnf

在 [client] 下增加 default-character-set=utf8
在 [mysqld] 下增加 default-character-set=utf8
collation_server = utf8_general_ci

在[mysqld] 下增加 init_connect=’SET NAMES utf8’
然后重启mysql

service mysqld restart

进入 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)