mysql啟動報錯
今天啟動mysql又一次報錯:The server quit without updating PID file!記得上次出現這個問題的時候,嘗試了一些常規的方法,未果,所以索性重新進行安裝。但是,相同的問題今天又出現了!!!OH, my god!恰巧今天時間充裕,嘗試各種辦法,終於皇天不負有心人,經過一個小時的奮戰后,終於讓我給搞定,整個過程是這樣的!
解決過程
首先,按着自己思路去查看日志文件,相信大家能看到的最多的內容就是Innodb,這是什么玩意兒?其實日志中的信息基本沒啥用,就不浪費太多時間了。
然后,使用最直接的辦法——百度。相信很多人搜到的結果都是以下幾項:
- 可能是/usr/local/mysql/data/mysql.pid文件沒有寫的權限 解決方法 :給予權限,執行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data” 然后重新啟動mysqld!
- 可能進程里已經存在mysql進程 解決方法:用命令“ps -ef|grep mysqld”查看是否有mysqld進程,如果有使用“kill -9 進程號”殺死,然后重新啟動mysqld!
- 可能是第二次在機器上安裝mysql,有殘余數據影響了服務的啟動。 解決方法:去mysql的數據目錄/data看看,如果存在mysql-bin.index,就趕快把它刪除掉吧,它就是罪魁禍首了。
- mysql在啟動時沒有指定配置文件時會使用/etc/my.cnf配置文件,請打開這個文件查看在[mysqld]節下有沒有指定數據目錄(datadir)。 解決方法:請在[mysqld]下設置這一行:datadir = /usr/local/mysql/data
- skip-federated字段問題 解決方法:檢查一下/etc/my.cnf文件中有沒有沒被注釋掉的skip-federated字段,如果有就立即注釋掉吧。
- 錯誤日志目錄不存在 解決方法:使用“chown” “chmod”命令賦予mysql所有者及權限
- selinux惹的禍,如果是centos系統,默認會開啟selinux 解決方法:關閉它,打開/etc/selinux/config,把SELINUX=enforcing改為SELINUX=disabled后存盤退出重啟機器試試
抱着試試看的態度,我把上面所有方法都嘗試了一遍,結果。。。然並卵!我的所有文件的權限都沒問題,所屬主和所屬組也沒問題,也沒有找到所謂的mysql-bin.index文件,日志文件也有!!!心想,what are you 弄啥嘞??? 繼續搜索,在這里 https://serverfault.com/questions/457337/mysql-server-quit-without-updating-pid-file 看到一個成功案例,方法如下: Try moving the /var/lib/mysql/ibdata1, /var/lib/mysql/ibdata2 and so on to another directory and start the server again. It should rebuild the index files. Once it did and you verified everything is working again, you can remove the old corrupted ones. 意思是說:刪除mysql的庫文件下的ibdata*文件。 我毫不猶豫的照做了,然后啟動mysql,當時啟動界面有點不一樣,我竊喜,終於搞定,可是誰知道結果卻是:
[root@localhost mysql]# /etc/init.d/mysqld start Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'. ./usr/local/mysql/bin/mysqld_safe: 行 178: 3588 已殺死 nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock < /dev/null > /dev/null 2>&1 ERROR! The server quit without updating PID file (/data/mysql/localhost.localdomain.pid). [root@localhost mysql]# /etc/init.d/mysqld start Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'. .. ERROR! The server quit without updating PID file (/data/mysql/localhost.localdomain.pid).
總之問題還沒解決! 於是繼續查找原因,嘗試各種辦法更改配置文件,但是仍然沒搞定,最后我在此查看錯誤日志:
[root@localhost mysql]# less localhost.localdomain.err 2017-08-18 13:42:30 3905 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2017-08-18 13:42:30 3905 [Note] InnoDB: Database physically writes the file full: wait... 2017-08-18 13:42:30 3905 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2017-08-18 13:42:35 3905 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2017-08-18 13:42:39 3905 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2017-08-18 13:42:39 3905 [Warning] InnoDB: Creating New log files failed, the ib_ligfile existed。
看到這,我突然想到刪除mysql庫文件/data/mysql/中的“ib_*”文件,一不做二不休,反正是在虛擬機中操作,大不了重新安裝,於是我執行如下操作:
** 注意:** 執行該操作之前一定要對數據庫進行備份,因為ibdata1存放的是所有數據文件,如果不小心刪了庫,那就慘了!!!(傳說中的從刪庫到跑路。。。)
[root@localhost mysql]# ls aria_log.00000001 ib_buffer_pool ib_logfile101 mysql aria_log_control ibdata1 localhost.localdomain.err performance_schema auto.cnf ib_logfile0 multi-master.info test [root@localhost mysql]# rm -rf ib_buffer_pool ib_logfile101 ibdata1 localhost.localdomain.err ib_logfile0
然后重啟:
[root@localhost mysql]# /etc/init.d/mysqld start Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'. ....... SUCCESS!
這個結果讓我大吃一驚,我有點不敢相信,於是又執行下面的操作:
[root@localhost mysql]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL..... SUCCESS! [root@localhost mysql]# ps aux |grep mysql root 3976 0.0 0.0 113256 16 pts/0 S 13:42 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid mysql 4112 0.0 74.4 964872 366432 pts/0 Sl 13:42 0:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock root 4170 0.0 0.1 112664 972 pts/0 S+ 14:21 0:00 grep --color=auto mysql [root@localhost mysql]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1662/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2050/master tcp6 0 0 :::3306 :::* LISTEN 4112/mysqld tcp6 0 0 :::22 :::* LISTEN 1662/sshd tcp6 0 0 ::1:25 :::* LISTEN 2050/master
到這里,我終於安心了,確實解決了,於是趕緊寫下文章分析一下個人心得!不過,由於專業知識薄弱,小白沒能明白其中的原理,希望有高人在評論中指點,不勝感激!!!
補充:
2017年8月25日補充。 今天又看到類似的報錯,但是並沒有影響登錄使用mysql,查看日志有這樣的字樣“initialize buffer pool,size=128.0M”,“cannot allocate memory for the pool”,大概意思是說無法分配足夠的內存供pool使用。此時想到mysql配置文件中有相關的配置,於是更改如下參數:
innodb_buffer_pool_size = 128 #配置文件中該值默認為128M
將這個值調小,再次啟動mysql服務,問題解決!
補充2:
查看日志有如下錯誤提示:Plugin 'InnoDB' registration as a STORAGE ENGINE failed。 解決辦法:
[root@localhost mysql]# rm -rf ib_logfile*
然后啟動mysql,問題解決!
(adsbygoogle = window.adsbygoogle || []).push({});
本文參與騰訊雲自媒體分享計划,歡迎正在閱讀的你也加入,一起