linux下mysql中文乱码
登录mysql执行
mysql> show variables like 'character%';
发现编码有些不是utf-8
修改/etc/mysql/my.cnf,网上说的是/etc/my.cnf但是没在这个位置找到
然后在[client]中添加
default-character-set=utf8
[mysql]中添加
default-character-set=utf8
[mysqld]中添加
collation-server = utf8_unicode_ci
init-connect=’SET NAMES utf8′ (引号貌似有问题)
character-set-server = utf8
保存退出
停止mysql服务
sudo service mysql stop
再启动mysql服务
sudo service mysql start
查看状态
sudo service mysql status
登录mysql再执行
mysql> show variables like 'character%';
看到编码已经被改变
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)
2016-12-26
mac下解决乱码问题:
mac下/etc目录下默认是没有mysql的配置文件的
但是我们可以把默认的配置文件拷贝到这里
终端输入以下命令,把mysql的默认配置文件拷贝到/etc目录下
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
接下来的步骤就和Linux上的解决方案相同了
参考链接:
http://www.ha97.com/5359.html
http://www.111cn.net/sys/linux/53209.htm
http://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/
原文收集链接:http://www.cnblogs.com/ieayoio/p/5460669.html