mysql 字符集


乱码

问题描述

乱码,一般是中文乱码。


原因分析

MySQL会出现中文乱码的原因不外乎下列几点:
1.server本身设定问题,例如还停留在latin1
2.table的语系设定问题(包含character与collation)
3.客户端程式(例如php)的连线语系设定问题

http://blog.csdn.net/luoweifu/article/details/8832492


解决方法

修改字符集。





修改字符集

问题描述

之前以为修好mysql的字符集是用set命令,今天发现用set命令设置字符集之后,如果重启mysql的话,结果又是和配置文件里的字符集是一样的,而不是刚刚用set命令设置的字符集。换句话说,set命令设置字符集只是暂时起作用,一旦重启mysql之后,就又恢复到之前的字符集。


原因分析

同上。

解决方法

那么,该如何修改mysql的字符集呢?只有在配置文件里修改咯,并且修改完之后,要重启mysql。


具体怎么修改?

1、windows版本

修改配置文件里的字符集。


修改2个地方,一个是mysql服务器本身的字符集,一个是客户端的字符集(客户端字符集是干嘛的?待研究!)。

# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]

port=3306

[mysql]

default-character-set=utf8

# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
#
[mysqld]

# The TCP/IP Port the MySQL Server will listen on
port=3306


#Path to installation directory. All paths are usually resolved relative to this.
basedir="C:/Program Files (x86)/MySQL/MySQL Server 5.5/"

#Path to the database root
datadir="C:/ProgramData/MySQL/MySQL Server 5.5/Data/"

# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8


2、linux版本

没看到配置文件里有字符集,所以添加一个字符集。


只需添加一个地方,那就是mysql服务器的字符集。

[mysqld]
# Settings user and group are ignored when systemd is used (fedora >= 15).
# If you need to run mysqld under different user or group, 
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
user=mysql

character_set_server = utf8

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock


注:不论是修改字符集,还是添加字符集,都不要放错了地方,而应该放在对应的mysql服务器配置段落或者客户端配置段落,否则重启mysql时可能会重启失败。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值