> 数据库 > MySQL >

CentOS 6.1下设置MySQL 5.21 字符集设置(gbk)

1. 解决办法: cp /usr/share/mysql/my-medium.cnf /etc/my.cnf ; 
2. 编辑:增加两个编码变量 
[client]
default-character-set=gbk

[mysqld]
character_set_server=gbk
datadir=/var/lib/mysql

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

3. 重启mysql即可。
------------------------------------------------------------------------------------------------------------------------------------
1.由于在开发中C++ ,java,asp.net, jsp等程序中使用gbk作为数据库操作编码的话,并且创建表时也是用了gbk编码,由于mysql使用的是utf-8的编码,这样在程序语言里查询数据库时,会导致数据获取不到的问题。

     2. 设置MySQ.L的字符集时,网上大多是在配置文件my.cnf中的[client]和[mysqld]下增加:default-character-set=gbk,但是配置完之后你重启MySQL服务器时,要么MySQL服务器会卡死在哪里启动不了(ubuntu),或者重启mysql时报错:The server quit without updating PID file .......;查询日志:/var/lib/mysql/"主机名".err文件得知,问题原因是由于当前版本的mysql的配置文件上my.cnf中的[mysqld]下的default-character-set变量不被识别,正确的解决办法是在[mysqld]下:设置character_set_server=gbk

===========下面的内容转自网络=================
解决Starting MySQL. ERROR! The server quit without updating PID file 

2011-6-21 23:25| 发布者: ishagua| 查看: 2362| 评论: 0|原作者: ishagua
摘要: 首先告诉你一条超级有用的定理,Linux 系统出错的时候一定要先查看错误日志: #cat /var/lib/mysql/'主机名'.err

mysqld_safe mysqld from pid file /var/lib/mysql/...- ...首先告诉你一条超级有用的定理,Linux 系统出错的时候一定要先查看错误日志:

#cat /var/lib/mysql/'主机名'.err

110621 13:07:44 mysqld_safe mysqld from pid file /usr/local/mysql/data/www.pc-pub.com.pid ended
110621 13:10:28 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
110621 13:10:28 [ERROR] COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'utf8'
110621 13:10:28 [ERROR] Aborting

110621 13:10:28 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

艹:是字符集和字符冲突了,所以编译的时候要把字符和字符集选项都加上,并且要兼容!修改编译参数:

#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EMBEDDED_SERVER=1 -DWITH_SSL=system

艹,还是有错,再抓日志看看:

#cat /usr/local/mysql/data/www.pc-pub.com.err

110621 13:58:19 [Note] Recovering after a crash using mysql-bin
110621 13:58:19 [Note] Starting crash recovery...
110621 13:58:19 [Note] Crash recovery finished.
110621 13:58:19 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
110621 13:58:19 mysqld_safe mysqld from pid file /usr/local/mysql/data//www.pc-pub.com.pid ended


这是啥意思呢?这是权限问题!(先修改配置文件再初始化数据库即可!)


[root@www mysql-5.5.13]# /etc/init.d/mysql start
Starting MySQL.. SUCCESS!


记住:Linux 系统下发现有错误,记得一定要先查看日志,这样才能在学习中不断进步!  (责任编辑:IT)