Mac 修改MYSQL 的默认编码格式 解决中文插入MySql里乱码

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

一、在系统偏好设置里,停止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

--------------



这样就解决了中文乱码啦。。。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值