当前位置:Gxlcms > mysql > CentOS6.1MySQL5.21字符编码设置(gbk)

CentOS6.1MySQL5.21字符编码设置(gbk)

时间:2021-07-01 10:21:17 帮助过:29人阅读

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 系统下发现有错误,记得一定要先查看日志,这样才能在学习中不断进步!

人气教程排行