Home >Database >Mysql Tutorial >MySQL中如何解决中文乱码问题

MySQL中如何解决中文乱码问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:00:191240browse

MySQL 字符集一. 显示字符集mysqladmin -uroot -proot variables | grep character| character_set_client | latin1 || characte

MySQL 字符集

一. 显示字符集
mysqladmin -uroot -proot variables | grep character

| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/share/mysql/charsets/ |

数据库缺省使用latin1 (ISO-8859)


二. 配置字符集

1. 建库时配置字符集

create database testxxx default charset=utf8

3. 建表时配置字符集

CREATE TABLE `t_agent` (
`ID` smallint(5) NOT NULL
) DEFAULT CHARSET=utf8 ;

4. 修改字符集

Windows平台
windows下的mysql配置文件是my.ini,一般在c:\windows\my.ini或者c:\winnt\my.ini可以直接在这个文件里面加上
default-character-set=gbk #或gb2312,big5,utf8
然后重新启动mysql
service mysql restart

/etc/init.d/mysql restart
或用其他方法重新启动,就生效了。

[编辑]Unix平台
linux下的mysql配置文件是my.cnf,一般是/etc/my.cnf,,如果找不到可以用find命令找一下:
find / -iname my.cnf
在这个文件里面加上
default-character-set=gbk #或gb2312,big5,utf8
然后重新启动mysql

三. 配置排序字符集

myisamchk -r -q --set-character-set=charset

四. 启动数据库时修改字符集

./mysqld_safe --character-set-server=utf8 --skip-character-set-client-handshake --user=root &

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn