MySql启动出现The server quit without updating PID file错误解决过程

看了大家的评论,先说解决办法(有兴趣的继续看,没兴趣的忽略下面的):删除/etc/mysql/my.conf

此次错误是在一次正常开机之后出现的,当时phpmyadmin登陆的时候出现#2002错误,然后我在bash中执行mysql命令无法连接,出现错误:

 

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

查看进程是否存在僵尸进程


#ps -aux|grep mysql

没有发现mysql相关进程,然后启动mysql服务


#service mysql start

出现错误


The server quit without updating PID file (/var/run/mysqld/mysqld.pid).

查看错误日志,发现没有开启错误日志记录,开启错误日志记录,


#vim /etc/my.cnf

添加下面的语句:


log_error = /var/log/mysql/error.log

创建错误日志目录


#mkdir /var/log/mysql

再次启动MySql服务,查看错误日志:


141110 11:41:33 [ERROR] Can't find messagefile '/usr/share/mysql/errmsg.sys'

然后从源码包复制errmsg.sys文件到/usr/share/mysql/ 再次启动MySql服务,还是失败,查看日志:


141110 18:54:38 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var/lib/mysql

我的MySql数据库目录是在 /usr/local/mysql/var/mysql,修改my.cnf,将datadir的值修改为 /usr/local/mysql/var,悲催的是启动之后再次出错,错误日志如下:


141110 19:01:43 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var/mysql
141110 19:01:43 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
141110 19:01:43 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
/usr/local/mysql/bin/mysqld: Table 'mysql.plugin' doesn't exist
141110 19:01:43 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
141110 19:01:43 InnoDB: The InnoDB memory heap is disabled
141110 19:01:43 InnoDB: Mutexes and rw_locks use GCC atomic builtins
141110 19:01:43 InnoDB: Compressed tables use zlib 1.2.8
141110 19:01:43 InnoDB: Initializing buffer pool, size = 16.0M
141110 19:01:43 InnoDB: Completed initialization of buffer pool
141110 19:01:43 InnoDB: highest supported file format is Barracuda.
141110 19:01:43  InnoDB: Waiting for the background threads to start
141110 19:01:44 InnoDB: 5.5.37 started; log sequence number 1999196
141110 19:01:44 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
141110 19:01:44 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
141110 19:01:44 [Note] Server socket created on IP: '127.0.0.1'.
141110 19:01:44 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
141110 19:01:44 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

上网搜索了一下,初始化MySql数据库,先删除MySql数据库,然后初始化


#mv /usr/local/var/mysql /usr/local/var/mysql_bak
#/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var

执行mysql_install_db命令的时候后面的参数一定要加上,--user代表运行用户,--basedir代表MySql安装目录,--datadir代表数据库数据所在目录,每个人的配置不一样,根据自己的修改一下。 执行命令之后系统给出下面的提示:


Installing MySQL system tables...
141110 19:13:20 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
OK
Filling help tables...
141110 19:13:20 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h killer-Lenovo-IdeaPad-Y480 password 'new-password'

Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

/usr/local/var/目录下面也确实生成了mysql目录,但是还是无法启动MySql,每个目录该给的权限都给了,所有者以及所有组都改成mysql了,但是还是不行,网上各种方法也都试了,最后无果,就在CSDN上面提出了问题,有个热心网友回答了我的问题,他给了一个链接,其实那个链接的文章我看过了,但是看到删除my.cnf的时候我突然想到/etc/mysql/下面也有个my.cnf文件,于是删除了那个文件,启动MySql服务,成功了!