程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> MySQL啟動故障處理小記

MySQL啟動故障處理小記

編輯:MySQL綜合教程

 之前啟動MySQL時,就不太正常,要多重啟幾次,不過能啟動,也就沒放在心上,今天測試測試又出現了問題,MySQL 啟動正常,但是無法關閉:
 
[root@rac2 mysql]# service mysql stop
MySQL server PID file could not befound!                  [FAILED]
[root@rac2 mysql]# ./mysql.server stop
MySQL server PID file could not befound!                  [FAILED]
 
這裡提示的PID 文件指:/var/lib/mysql/rac2.pid,該文件和/var/lib/mysql/mysql.sock 文件一樣,僅在MySQL 運行時存在,後來的驗證如下:
 
[root@rac2 lib]# ls /var/lib/mysql/rac2.pid
/var/lib/mysql/rac2.pid
[root@rac2 lib]# service mysql stop
Shutting down MySQL.                                       [  OK  ]
[root@rac2 lib]# ls /var/lib/mysql/rac2.pid
ls: /var/lib/mysql/rac2.pid: No such fileor directory
 
 所以當我的MySQL 運行正常時,應該是存在這個文件的,google的一個說法是my.cnf 參數文件的basedir 參數錯誤,注釋掉這個參數即可,但是我都沒有設過這個參數,所以和這個應該沒有關系。
 
查看了一下默認值:
mysql> show variables like '%basedir%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| basedir       | /usr |
+---------------+-------+
1 row in set (0.00 sec)
 
[root@rac2 ~]# ps -ef|grep mysql
root     2161     1  0 09:38 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe--datadir=/var/lib/mysql --pid-file=/var/lib/mysql/rac2.pid
mysql    2418  2161  0 09:38 ?        00:00:00 /usr/sbin/mysqld --basedir=/usr--datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql--log-error=/var/lib/mysql/rac2.err --pid-file=/var/lib/mysql/rac2.pid--socket=/var/lib/mysql/mysql.sock --port=3306
root     3628  3596  0 09:57 pts/1    00:00:00 grep mysql
 
--log信息
[root@rac2 ~]#cat /var/lib/mysql/rac2.err
111129 9:38:49 [Note] Plugin 'FEDERATED' is disabled.
111129 9:38:49 InnoDB: The InnoDB memory heap is disabled
111129 9:38:49 InnoDB: Mutexes and rw_locks use GCC atomic builtins
111129 9:38:49 InnoDB: Compressed tables use zlib 1.2.3
111129 9:38:49 InnoDB: Using Linux native AIO
111129 9:38:49 InnoDB: Initializing buffer pool, size = 128.0M
111129 9:38:50 InnoDB: Completed initialization of buffer pool
111129 9:38:50 InnoDB: highest supported file format is Barracuda.
111129 9:38:50  InnoDB: Waiting for thebackground threads to start
111129 9:38:51 InnoDB: 1.1.8 started; log sequence number 1605950
111129 9:38:52 [Note] Event Scheduler: Loaded 0 events
111129 9:38:52 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.15-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306 MySQL Community Server (GPL)
111129 10:50:36 mysqld_safe Starting mysqlddaemon with databases from /var/lib/mysql
111129 10:50:37 [Note] Plugin 'FEDERATED'is disabled.
111129 10:50:37 InnoDB: The InnoDB memoryheap is disabled
111129 10:50:37 InnoDB: Mutexes andrw_locks use GCC atomic builtins
111129 10:50:37 InnoDB: Compressed tablesuse zlib 1.2.3
111129 10:50:37 InnoDB: Using Linux nativeAIO
111129 10:50:37 InnoDB: Initializing bufferpool, size = 128.0M
111129 10:50:37 InnoDB: Completedinitialization of buffer pool
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already haveanother mysqld process
InnoDB: using the same InnoDB data or logfiles.
111129 10:50:37  InnoDB: Retrying to lock the first data file
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already haveanother mysqld process
InnoDB: using the same InnoDB data or logfiles.

InnoDB: Check that you do not already haveanother mysqld process
InnoDB: using the same InnoDB data or logfiles.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already haveanother mysqld process
--這個提示的意思有多個mysqld 進程在運行。
 
 
解決方法:
(1)重新用:ps -ef|grep mysql 查詢所有的進程,然後把所有的進程kill掉,
(2)重新對相關的目錄賦權
[root@rac2 /]# chown mysql.mysql -R/var/lib/mysql/*
[root@rac2 /]# chmod 755 -R/var/lib/mysql/*
 
--再次啟動成功:
[root@rac2 /]# service mysql start
Starting MySQL......                                       [  OK  ]
[root@rac2 /]# ps -ef|grep mysql
root    27936     1  1 14:08 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe--datadir=/var/lib/mysql --pid-file=/var/lib/mysql/rac2.pid
mysql   28193 27936  3 14:08 pts/1    00:00:00 /usr/sbin/mysqld --basedir=/usr--datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql--log-error=/var/lib/mysql/rac2.err --pid-file=/var/lib/mysql/rac2.pid--socket=/var/lib/mysql/mysql.sock --port=3306
root    28220  3596  0 14:08 pts/1    00:00:00 grep mysql
[root@rac2 /]# ll /var/lib/mysql/mysql.sock
srwxrwxrwx 1 mysql mysql 0 Nov 29 14:08/var/lib/mysql/mysql.sock
 
再次查看log:
[root@rac2 lib]#  tail -20 /var/lib/mysql/rac2.err
111129 14:51:53 [Note] Event Scheduler:Purging the queue. 0 events
111129 14:51:53  InnoDB: Starting shutdown...
111129 14:51:54  InnoDB: Shutdown completed; log sequencenumber 1605950
111129 14:51:54 [Note] /usr/sbin/mysqld:Shutdown complete
 
111129 14:51:54 mysqld_safe mysqld from pidfile /var/lib/mysql/rac2.pid ended
111129 14:53:34 mysqld_safe Starting mysqlddaemon with databases from /var/lib/mysql
111129 14:53:34 [Note] Plugin 'FEDERATED'is disabled.
111129 14:53:34 InnoDB: The InnoDB memoryheap is disabled
111129 14:53:34 InnoDB: Mutexes andrw_locks use GCC atomic builtins
111129 14:53:34 InnoDB: Compressed tablesuse zlib 1.2.3
111129 14:53:34 InnoDB: Using Linux nativeAIO
111129 14:53:34 InnoDB: Initializing bufferpool, size = 128.0M
111129 14:53:34 InnoDB: Completed initializationof buffer pool
111129 14:53:35 InnoDB: highest supportedfile format is Barracuda.
111129 14:53:35 InnoDB:1.1.8 started; log sequence number 1605950
111129 14:53:35 [Warning] Neither--relay-log nor --relay-log-index were used; so replication may break when thisMySQL server acts as a slave and has his hostname changed!! Please use'--relay-log=rac2-relay-bin' to avoid this problem.
111129 14:53:35 [Note] Event Scheduler:Loaded 0 events
111129 14:53:35 [Note]/usr/sbin/mysqld: ready for connections.
Version: '5.5.15-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306 MySQL Community Server (GPL)
[root@rac2 lib]#
 
 
說明:
       因為之前沒有保留的相關信息,修改之後,雖重復模擬多次,都不能還原當時的故障,所有缺少足夠多的一手資料來證明這個問題。但是我這裡的2種方法都可以嘗試一下:
   
MySQL server PID file could not befound! 
--可能是相關目錄的權限問題導致
 
Check that you do not already have anothermysqld process
--重復進程導致,可以先ps,在kill掉相關進程在重試。


作者 tianlesoftware
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved