最近开始在ubuntu下玩耍了,哈哈哈,可是mysql一直乱码,在网上找了几篇文章,但是修改之后一直报ERROR 2002 (HY000): Can
't connect to local MySQL server through socket '
/var/run/mysqld/mysqld
.sock' (2)这个奇葩的错误,继续苦逼的寻找,最后发现原来是顺序的问题,一定要按下面的顺序修改:
打开mysql配置文件 : sudo vi /etc/mysql/my.cnf
在[client]节点下最后一行添加
default-character-set=utf8
在[mysqld_safe]下最后一行添加
default-character-set=utf8
在[mysqld]下第一行添加
lower_case_table_names=1
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
重启mysql:sudo service mysql restart
重新查看
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
show variables like 'collation_%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
哈哈,世界又美好了……
参考:http://tcrct.iteye.com/blog/1664262