首页 » web服务器

LNMP安装常见问题集锦 ② 、mysql

   发表于:web服务器评论 (0)   热度:2451


1、Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/mylinux.pid).
出现情况:运行" service mysqld start"或者" /etc/init.d/mysqld start" 启动mysqld守护进程的时
错误意思:重启mysql失败,原因是找不到

 

解决办法: 

 

 

解决方法一、

从报错上看,看不出具体问题,只能看日志了
[root@mylinux /]# cd /usr/local/mysql/data
[root@mylinux data]# tail -f -n 20 mylinux.err

130623 16:34:53 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
130623 16:34:53 [Note] Plugin 'FEDERATED' is disabled.
130623 16:34:53 InnoDB: The InnoDB memory heap is disabled
130623 16:34:53 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130623 16:34:53 InnoDB: Compressed tables use zlib 1.2.3
130623 16:34:53 InnoDB: Initializing buffer pool, size = 128.0M
130623 16:34:53 InnoDB: Completed initialization of buffer pool
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
130623 16:36:33  InnoDB: Unable to open the first data file
InnoDB: Error in opening ./ibdata1
130623 16:36:33  InnoDB: Operating system error number 11 in a file operation.
InnoDB: Error number 11 means 'Resource temporarily unavailable'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/operating-system-error-codes.html
130623 16:36:33 InnoDB: Could not open or create data files.
130623 16:36:33 InnoDB: If you tried to add new data files, and it failed here,
130623 16:36:33 InnoDB: you should now edit innodb_data_file_path in my.cnf back
130623 16:36:33 InnoDB: to what it was, and remove the new ibdata files InnoDB created
130623 16:36:33 InnoDB: in this failed attempt. InnoDB only wrote those files full of
130623 16:36:33 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
130623 16:36:33 InnoDB: remove old data files which contain your precious data!
130623 16:36:33 [ERROR] Plugin 'InnoDB' init function returned error.
130623 16:36:33 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
130623 16:36:33 [ERROR] Unknown/unsupported storage engine: InnoDB
130623 16:36:33 [ERROR] Aborting
130623 16:36:33 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
130623 16:36:33 mysqld_safe mysqld from pid file /usr/local/mysql/data/mylinux.pid ended

出现情况: 查看以上日志很明显是一句  InnoDB: Check that you do not already have another mysqld process
说明已经有mysqld进程在运行了,所以启动mysql失败。
解决办法:
[root@mylinux etc]# ps -ef|grep mysqld
[root@mylinux etc]# kill -9  进程号
[root@mylinux etc]# service mysqld start
这是启动一次 mysql 报的具体的错误。
我重启了一下CentOS服务器,再重启一下mysqld,问题自己解决了,可能是由于LVM磁盘管理软件的原因。

google了下 ,出现这个问题可能的原因有多种,具体什么原因最好的办法是先查看下错误日志:
1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限
解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data”  然后重新启动mysqld!
2.可能进程里已经存在mysql进程
解决方法:用命令“ps -ef|grep mysqld”查看是否有mysqld进程,如果有使用“kill -9  进程号”杀死,然后重新启动mysqld!
3.可能是第二次在机器上安装mysql,有残余数据影响了服务的启动。
解决方法:去mysql的数据目录/data看看,如果存在mysql-bin.index,就赶快把它删除掉吧,它就是罪魁祸首了。本人就是使用第三条方法解决的 !http://blog.rekfan.com/?p=186
4.mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录(datadir)。
解决方法:请在[mysqld]下设置这一行:datadir = /usr/local/mysql/data
5.skip-federated字段问题
解决方法:检查一下/etc/my.cnf文件中有没有没被注释掉的skip-federated字段,如果有就立即注释掉吧。
6.错误日志目录不存在
解决方法:使用“chown” “chmod”命令赋予mysql所有者及权限
7.selinux惹的祸,如果是centos系统,默认会开启selinux
解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试。
8.mysql的data目录挂载的磁盘空间已经用完

解决方法:df -h 查看磁盘使用情况,果然磁盘满了,因为当时分区采用系统默认,不知道为什么不能自动扩容然后清理多余数据,以后在研究吧。启动mysql,成功启动!

 

 

解决方法 二、

问题起因:
今天做了一件事情:我在VM 上将一数据库的数据文件(/var/lib/mysql整个文件夹)拷贝到另外一台VM上,然后新的VM 上启动MYSQL,结果报如下异常:
[root@localhost mysql]# service mysql start
Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
于是Google之,大部分的答案都是:
1. 注释/etc/my.cnf里的skip-federated注释掉即#skip-federated;
2. my.cnf文件配置过高,重新定义其中的参数(根据服务器情况定义);
3. 杀掉mysql_safe和mysqld进程,然后再重启;
4. 当前日志文件过大,超出了my.cnf中定义的大小(默认为64M),删除日志文件再重启;
5. 其他情况,查看日志文件(我的是localhost.localdomain.err,具体因人而异),然后具体分析;

问题解决:
其中,我查看了日志内容,如下:
[root@localhost mysql]# less localhost.localdomain.err 
111203 22:09:03 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
^G/usr/sbin/mysqld: File './mysql-bin.index' not found (Errcode: 13)
111203 22:09:03 [ERROR] Aborting

111203 22:09:03 [Note] /usr/sbin/mysqld: Shutdown complete

111203 22:09:03 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended

但是我查看了我的目录文件,mysql-bin.index文件是存在的呀,奇怪:
[root@localhost mysql]# ll
total 49828
-rw-rw----. 1 mysql mysql 35651584 Dec  3 17:55 ibdata1
-rw-rw----. 1 mysql mysql  5242880 Dec  3 17:55 ib_logfile0
-rw-rw----. 1 mysql mysql  5242880 Dec  3 15:45 ib_logfile1
-rw-rw----. 1 mysql root      1376 Dec  3 22:02 localhost.localdomain.err
drwx--x--x. 2 mysql mysql     4096 Dec  3 17:55 mysql
-rw-rw----. 1 mysql mysql  4847020 Dec  3 17:55 mysql-bin.000001
-rw-rw----. 1 mysql mysql     1373 Dec  3 17:56 mysql-bin.000002
-rw-r--r--. 1 root  root        19 Dec  3 15:38 mysql-bin.index
drwx------. 2 mysql mysql     4096 Dec  3 17:55 performance_schema
-rw-r--r--. 1 root  root       116 Nov 25 21:03 RPM_UPGRADE_HISTORY
-rw-r--r--. 1 mysql mysql      116 Nov 25 21:03 RPM_UPGRADE_MARKER-LAST
drwxr-xr-x. 2 mysql mysql     4096 Dec  3 17:55 test
仔细看了下,咦?-rw-r--r--. 1 root  root        19 Dec  3 15:38 mysql-bin.index----难道是权限不够?于是将该文件加了写权限,重启,涛声依旧!!!噢噢!

难道是编码问题?难道是....继续猜测。。。问题还是没解决,后来我做了一件事情,将mysql-bin.index文件删除掉!重启!!OH!No!!
[root@localhost mysql]# rm -rf mysql-bin.index 
[root@localhost mysql]#  
[root@localhost mysql]# service mysql start
Starting MySQL... SUCCESS! 

就这样??为什么呢?至今这个仍然是未解之谜(对我来说),如有知情者请告知:)

补充:
很多时候,我们在做主从同步的时候,将数据库目录整体打包拷贝到从机上的时候,重启也往往会出现类似的问题,解决方法仍然是:
1)给MYSQL数据库数据目录权限:chown -R mysql:mysql 目录名称
2)务必保证MYSQL的进程是已经关闭了的;

另外要注意的地方就是:ib_*, mysql-bin-*, *.err(log文件)以及master-info和relay-info文件都是可以删除的,相当于重新初始化数据库的数据,但是前提是:
1)操作前要先关掉MYSQL的进程;
2)删掉文件后要重新启动MYSQL,如果有异常,请自行查看日志找问题,一般都比较好定位和解决。

(。・v・。)
喜欢这篇文章吗?欢迎分享到你的微博、QQ群,并关注我们的微博,谢谢支持。