1.查找MySQL的cnf文件的位置
# find / -iname '*.cnf' -print
2. 拷貝 my-small.cnf、my-medium.cnf、my-huge.cnf、my-innodb-heavy-4G.cnf 其中的任意一個到/etc下,並重命名為my.cnf
# cp /usr/share/mysql/my-small.cnf /etc/my.cnf
3. 查看mysql默認的字符集
[root@wiki ~]# mysql -u root -p
mysql> show variables like 'collation_%'; ==== 查看排序方式設定
mysql> show variables like 'character_set_%'; ==== 查看系統的字符集
==== mysql 默認用的字符集是latin1,連接校對用的latin1-_swedish_ci ====
4. 修改my.cnf
# vi /etc/my.cnf
在[client]下添加
default-character-set=utf8
在[mysqld]下添加
default-character-set=utf8
5. 重新啟動MySQL
[root@wiki ~]# /etc/rc.d/init.d/mysql restart
6. 查看字符集設置後的變化
[root@wiki ~]# mysql -u root -p
mysql> show variables like 'collation_%';
mysql> show variables like 'character_set_%';
===========================================================================================
其他的一些設置方法:
通過配置文件修改:
修改/var/lib/mysql/mydb/db.opt
default-character-set=latin1
default-collation=latin1_swedish_ci
為
default-character-set=utf8
default-collation=utf8_general_ci
重起MySQL:
[root@wiki ~]# /etc/rc.d/init.d/mysql restart
通過MySQL命令行修改:
mysql> set character_set_client=utf8;
mysql> set character_set_connection=utf8;
mysql> set character_set_database=utf8;
mysql> set character_set_results=utf8;
mysql> set character_set_server=utf8;
mysql> set character_set_system=utf8;
mysql> set collation_connection=utf8;
mysql> set collation_database=utf8;
mysql> set collation_server=utf8;
查看:
[root@wiki ~]# mysql -u root -p
mysql> show variables like 'character_set_%';
mysql> show variables like 'collation_%';
Images 0 | ||
---|---|---|
No images to display in the gallery. |