Linux服務器上的MySQL數據庫宕掉的原因

生產環境:

操作系統:CentOS release 6.8

數據庫系統:MySQL 5.5.52

分析問題:

一、客戶端訪問出現以下錯誤:

錯誤1:瀏覽器訪問Cacti監控系統

wKioL1mv-yjBVtbuAABIa3TZ3hU778.jpg-wh_50

FATAL: Cannotconnect to MySQL server on 'localhost'. Please make sure you have specified avalid MySQL database name in 'include/config.php'

錯誤2:瀏覽器訪問Discuz系統

Discuz! Database Error

The database has encountered a problem. Need Help?

   

Error messages:

  • [Type] 無法連接到數據庫服務器

  • [2002] Can't connect to       local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)


Program messages:

  • [Line:       0050]forum.php(discuz_core->init)

  • [Line:       0065]source/class/class_core.php(discuz_core->_init_db)

  • [Line:       0327]source/class/class_core.php(db_mysql->connect)

  • [Line:       0621]source/class/class_core.php(db_mysql->_dbconnect)

錯誤3:瀏覽器訪問BBS論壇

MYSQL 連接數據庫失敗,請確定數據庫用戶名,密碼設置正確
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'(2)
2002

錯誤4:由於mysql連接數太多,導致Toomany connections的問題

wKiom1mwnu2j_O9tAAAfvlCbt0c776.jpg

通過以上錯誤,基本上確定是數據庫出了問題。

二、進一步通過服務器來分析問題:

通過SecureCRT遠程登錄 Linux服務器,通過服務器來分析數據庫運行情況:

[root@sky9896/]# service mysqld status

mysqld (pid18965) 正在運行...    #實際上是一個假像,沒有真正啓動MySQL服務

[root@sky9896/]# lsof -i:3306     #沒有監測到3306端口

[root@sky9896/]# mysql -uroot –p     #無法登錄數據庫服務

ERROR 2002(HY000): Can't connect to local MySQL server through socket '/var

[root@sky9896 ~]# mysql -uroot -p

    Enter password:

    ERROR 1040 (HY000): Too many connections

[root@sky9896 ~]# service mysqld start

Timeout erroroccurred trying to start MySQL Daemon.   #啓動 mysqld 時經過很長時間顯示

正在啓動 mysqld                                          [失敗]

[root@sky9896httpd]# service mysqld start

MySQL Daemonfailed to start.

正在啓動 mysqld                                          [失敗]

[root@sky9896httpd]# service mysqld status

mysqld 已停

三、通過分析日誌來找到問題所在

[root@sky9896httpd]# tail  -100 /var/log/mysqld.log  170906 20:27:41 [Note] Plugin 'FEDERATED' isdisabled.

170906 20:27:41InnoDB: The InnoDB memory heap is disabled

170906 20:27:41InnoDB: Mutexes and rw_locks use GCC atomic builtins

170906 20:27:41InnoDB: Compressed tables use zlib 1.2.3

170906 20:27:41InnoDB: Using Linux native AIO

170906 20:27:41InnoDB: Initializing buffer pool, size = 128.0M

170906 20:27:41InnoDB: Completed initialization of buffer pool

170906 20:27:41InnoDB: highest supported file format is Barracuda.

17090620:27:41  InnoDB: Waiting for thebackground threads to start

170906 20:27:42InnoDB: 5.5.52 started; log sequence number 1648953943

170906 20:27:42[Note] Server hostname (bind-address): '0.0.0.0'; port: 3306

170906 20:27:42 [Note]   - '0.0.0.0' resolves to '0.0.0.0';

170906 20:27:42[Note] Server socket created on IP: '0.0.0.0'.

170906 20:27:42 [ERROR] /usr/libexec/mysqld: Error writingfile '/var/run/mysqld/mysqld.pid' (Errcode: 28)   #無法寫入文件到磁盤

170906 20:27:42 [ERROR] Can't start server: can't create PIDfile: No space left on device                            #不能創建PID文件

170906 20:27:42mysqld_safe Number of processes running now: 0

170906 20:27:42mysqld_safe mysqld restarted

170906 20:27:42[Note] libgovernor.so not found

170906 20:27:42[Note] /usr/libexec/mysqld (mysqld 5.5.52-cll-lve) starting as process 28237...

170906 20:27:42[Note] Plugin 'FEDERATED' is disabled.

170906 20:27:42InnoDB: The InnoDB memory heap is disabled

170906 20:27:42InnoDB: Mutexes and rw_locks use GCC atomic builtins

170906 20:27:42InnoDB: Compressed tables use zlib 1.2.3

四、嘗試啓動數據庫服務

[root@sky9896~]# /usr/bin/mysql_install_db

WARNING: Thehost 'sky9896' could not be looked up with resolveip.

This probablymeans that your libc libraries are not 100 % compatible

with this binaryMySQL version. The MySQL daemon, mysqld, should work

normally withthe exception that host name resolving will not work.

This means thatyou should use IP addresses instead of hostnames

when specifyingMySQL privileges !

Installing MySQLsystem tables...

170906 20:44:44[Note] libgovernor.so not found

170906 20:44:44[Note] /usr/libexec/mysqld (mysqld 5.5.52-cll-lve) starting as process 8472 ...

ERROR: 1030  Got error28 from storage engine   #28個表無法存儲

170906 20:44:45 [ERROR] Aborting

170906 20:44:45[Note] /usr/libexec/mysqld: Shutdown complete

Installation ofsystem tables failed!  Examine the logsin

/var/lib/mysqlfor more information.

You can try tostart the mysqld daemon with:

    shell> /usr/libexec/mysqld --skip-grant&

and use thecommand line tool /usr/bin/mysql

to connect tothe mysql database and look at the grant tables:

    shell> /usr/bin/mysql -u root mysql

    mysql> show tables

……

 通過上面的分析,確定磁盤空間不夠用。

[root@sky9896tmp]# df  -h

Filesystem      Size Used Avail Use% Mounted on

/dev/sda2       49G   47G     0   100%/    #49G-47G,還是無可用空間,

tmpfs           939M 100K  939M   1% /dev/shm

/dev/sda1        93M  54M   35M  61% /boot

/dev/sda5       179G 2.3G  168G   2% /home

 

[root@sky9896/]# du  -sh *   #查看文件大小

12K     a

152K    app

13G     application

6.7M    bin

52M     boot

4.0K    data

4.0K    data.php

340K    dev

326M    etc

2.2G    home

47M     html

318M    lib

20M     lib64

0       libmysqlclient_r.so

0       libmysqlclient.so

16K     lost+found

4.0K    media

8.0K    mnt

88M     oe

90M     opt

38M     root

53M     safedog_linux32

9.4M    sbin

376K    scripts

4.0K    selinux

42M     skyboy

4.0K    srv

14M     tmp

4.0K    usb

3.0G    usr

31G     var

[root@sky9896 www]# rm 5-*   #多刪除一些文件,騰出可用空間

rm:是否刪除普通文件"5-10第五課創業方式選擇故事5專家點評.rar"y

rm:是否刪除普通文件"5-1第五課創業方式選擇故事1教學案例.rar"?y

rm:是否刪除普通文件"5-2第五課創業方式選擇故事1專家點評.rar"?y

rm:是否刪除普通文件"5-3第五課創業方式選擇故事2教學案例.rar"?y

rm:是否刪除普通文件"5-4第五課創業方式選擇故事2專家點評.rar"?y

rm:是否刪除普通文件"5-5第五課創業方式選擇故事3教學案例.rar"?y

rm:是否刪除普通文件"5-6第五課創業方式選擇故事3專家點評.rar"?y

rm:是否刪除普通文件"5-7第五課創業方式選擇故事4教學案例.rar"?^Z

[3]+  Stopped                 rm -i 5-*

[root@sky9896www]# df -h

Filesystem      Size Used Avail Use% Mounted on

/dev/sda2       49G   45G  1.2G 98% /   #可用空間1.2G

tmpfs           939M 100K  939M   1% /dev/shm

/dev/sda1        93M  54M   35M  61% /boot

/dev/sda5       179G 2.3G  168G   2% /home

[root@sky9896www]# service mysqld start

正在啓動 mysqld:            [確定]    #數據庫服務正常啓動

小結,最終原因是Linux根目錄”/”下可使用空間不足,導致數據庫服務無法啓動。網上有許多解決方法,並不能實際解決,關鍵還是要查看運行日誌找問題。因作者是採用普通電腦架設Linux服務器,因上面跑了很多系統,導致空間驟增不夠用。

 

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章