>  기사  >  데이터 베이스  >  CentOS 6.1 MySQL 5.21 字符编码设置 (gbk)

CentOS 6.1 MySQL 5.21 字符编码设置 (gbk)

WBOY
WBOY원래의
2016-06-07 17:12:071023검색

CentOS 6.1 MySQL 5.21 字符编码设置 (gbk),由于在开发中C++ ,java,asp.net, jsp等程序中使用gbk作为数据库操作编码的话,并且创

解决办法: cp /usr/share/mysql/my-medium.cnf /etc/my.cnf ; 

编辑:增加两个编码变量 

[client]

default-character-set=gbk

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

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

上面设置好后,重启mysql即可。

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

login mysql

>show variables like 'character%';

The server quit without updating PID file 问题是由于当前版本的mysql中

[mysqld]中default-character-set变量不识别,正确答案是:设置character_set_server=gbk

通过baidu,查询的答案大都是在【mysqld】组中设置default-character-set=gbk
,所以导致重启mysql时 报 “The server quit without updating PID file”错误。查询日志:/var/lib/mysql/"主机名".err文件得知,default-character-set变量在[mysqld]中未定义。

===========下面的内容转自网络=================
解决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 系统下发现有错误,记得一定要先查看日志,这样才能在学习中不断进步!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.