一、在系统偏好设置里,停止MYSQL服务
二、查看mysql 的编码方式 : mysql>status;
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.5.50, for osx10.8 (i386) using readline 5.1
Connection id: 82
Current database:
Current user: jing@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.50 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 1 hour 58 min 41 sec
Threads: 16 Questions: 751 Slow queries: 0 Opens: 42 Flush tables: 1 Open tables: 28 Queries per second avg: 0.105
--------------
会看到mysql服务的编码方式是 latin1
三、查看 cd /etc/my.cnf,是否存在,如果不存在的话 执行
sudo cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
sudo vi /etc/my.cnf
[client]加入:
default-character-set=utf8
[mysqld]加入:
character-set-server=utf8
加完后如下:
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
default-character-set=utf8
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
character-set-server=utf8
四:再次执行 mysql>status;
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.5.50, for osx10.8 (i386) using readline 5.1
Connection id: 6
Current database:
Current user: jing@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.50-log MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 14 sec
Threads: 1 Questions: 19 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 1.357
--------------
这样就解决了中文乱码啦。。。

本文介绍如何通过修改MySQL配置文件my.cnf来解决MacOS环境下MySQL的中文乱码问题,包括调整服务编码方式为UTF-8的具体步骤。

被折叠的 条评论
为什么被折叠?



