linux mysql 查询乱码,linux mysql中文乱码解决

测试的机器是ubuntu 12.04个别linux发行版可能略有不同。

登陆mysql查看当前字符集命令:

mysql> show variable like '%char%';

+--------------------------+----------------------------+

| 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/ |

+--------------------------+----------------------------+

查看当前状态

mysql> status

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

mysql Ver 14.14 Distrib 5.5.34, for debian-linux-gnu (x86_64) using readline 6.2

Connection id:42

Current database:

Current user:test@localhost

SSL:Not in use

Current pager:stdout

Using outfile:''

Using delimiter:;

Server version:5.5.34-0ubuntu0.12.04.1 (Ubuntu)

Protocol version:10

Connection:Localhost via UNIX socket

Server characterset:utf8

Db characterset:utf8

Client characterset:utf8

Conn. characterset:utf8

UNIX socket:/var/run/mysqld/mysqld.sock

Uptime:46 min 52 sec

Threads: 4 Questions: 170 Slow queries: 0 Opens: 177 Flush tables: 1 Open tables: 42 Queries per second avg: 0.060

配置/etc/mysql/my.cnf文件:

找到[client]在[client]下面增加 default-character-set=utf8

[client]port= 3306socket= /var/run/mysqld/mysqld.sockdefault-character-set = utf8

找到[mysqld] 下面增加:

character-set-server =utf8

init_connect='SET NAMES utf8'

[mysqld]#

#*Basic Settings

#user =mysql

pid-file = /var/run/mysqld/mysqld.pid

socket= /var/run/mysqld/mysqld.sock

port= 3306basedir= /usr

datadir= /var/lib/mysql

tmpdir= /tmp

lc-messages-dir = /usr/share/mysql

skip-external-lockingcharacter-set-server=utf8

init_connect='SET NAMES utf8'

最后在[mysql]下增加 default-character-set=utf8

[mysql]

default-character-set=utf8

重启mysql就可以了

sudo /etc/init.d/mysql restart

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值