**********************************************************************

1、Starting MySQL...The server quit without updating PID file

修改了/etc/my.cnf后,启动mysql出现

# /etc/init.d/mysql start
Starting MySQL...The server quit without updating PID file [FAILED]b/mysql/localhost.localdomain.pid).
[mysqld]
character_set_server = utf8

查看mysql的错误日记
[root@localhost test1]# vi /var/lib/mysql/localhost.localdomain.err
可以看到
120516 16:26:11 [ERROR] /usr/sbin/mysqld: unknown variable 'default_set_server=utf8'
网上查了下,网友说MySQL5把字符变量改成了character_set_server
应该用character_set_server=utf8 取代default-character-set=utf8
重新启动mysql
# /etc/init.d/mysql start
Starting MySQL                                             [  OK  ]

**********************************************************************

2、MySQL中文乱码的问题。

>show variable like 'character%'; #执行编码显示
+-------------------------+----------------------------+
| Variable_nam | Value |
+-------------------------+----------------------------+
| character_se_client | latin1 |
| character_se_connection | latin1 |
| character_se_database | latin1 |
| character_se_filesystem | binary |
| character_se_results | latin1 |
| character_se_server | latin1 |
| character_se_system | utf8 |
| character_ses_dir | /usr/share/mysql/charsets/ |
+-------------------------+----------------------------+
--------------

# vi /etc/my.cnf

找到客户端配置[client] 在下面添加
### 默认字符集为utf8
default-character-set=utf8
在找到[mysqld] 添加
### 默认字符集为utf8
default-character-set=utf8
### (设定连接mysql数据库时使用utf8编码,以让mysql数据库为utf8运行)
init_connect='SET NAMES utf8'
修改好后,重新启动mysql 即可,查询一下show variables like 'character%';
##重新启动mysql
/etc/init.d/mysql restart

 

再次查看编码

+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |

这时直接在mysql数据库的控制台下插入和查询数据是不会出现乱码了。但C语言写的程序插入的数据仍为乱码,在执行插入数据的SQL语句时,在前面加上

MYSQL* pMyData;       //msyql 连接句柄
pMyData = mysql_init(NULL);
mysql_query(pMyData, "set character set utf8");  //加上这句

 

Linux下MySQL配置文件my.ini位置在哪里?

MySQL配置文件在Windows下叫my.ini,在MySQL的安装根目录下;在Linux下叫my.cnf,该文件位于/etc/my.cnf。

如果找不到/etc/my.cnf可以复制一份

# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

**********************************************************************

**********************************************************************

**********************************************************************
**********************************************************************

**********************************************************************
**********************************************************************

**********************************************************************
**********************************************************************

**********************************************************************
**********************************************************************


Logo

更多推荐