Mysql

無法在最近升級的 VM 上啟動 MySQL 服務

  • October 2, 2014

我有一個執行 Ubuntu 伺服器的虛擬機,我剛剛升級到 14.04。VM 提供對 MySQL 數據庫的訪問。但是,升級後,數據庫拒絕啟動,我對此知之甚少,無法弄清楚:

root@vm-1 ~ $ service mysql start
start: Job failed to start

我檢查/var/log/mysql/error.log並發現:

141001 20:23:10 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
141001 20:23:10 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
141001 20:23:10 [Note] Server socket created on IP: '127.0.0.1'.
141001 20:23:10 [ERROR] Can't start server : Bind on unix socket: Permission denied
141001 20:23:10 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld.sock ?
141001 20:23:10 [ERROR] Aborting

141001 20:23:10  InnoDB: Starting shutdown...
141001 20:23:11  InnoDB: Shutdown completed; log sequence number 24590151085
141001 20:23:11 [Note] /usr/sbin/mysqld: Shutdown complete

您可以在此處找到該文件的全部內容。請注意,我在執行上面顯示的命令之前刪除了它service,因此所有內容都來自一次嘗試啟動 MySQL 服務。

我還檢查了明顯的:

$ ps ax | grep mysql
3623 pts/1    S+     0:00 grep --color mysql
$ rm /var/run/mysqld/mysqld.sock
rm: cannot remove ‘/var/run/mysqld/mysqld.sock’: No such file or directory
$ netstat | grep 3306

我確保數據庫目錄具有正確的權限:

$ chown -R mysql:root /data/database/

我試著跑步strace,但看不到任何明顯的東西。不過我對它了解的很少,所以你可以在這裡找到輸出。

最後,我/etc/mysql/my.cnf的是:

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0
[mysqld]
user        = mysql
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /data/database
tmpdir      = /tmp
skip-external-locking
bind-address        = 127.0.0.1
key_buffer      = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
myisam-recover         = BACKUP
query_cache_limit   = 1M
query_cache_size        = 16M
log_error                = /var/log/mysql/error.log
expire_logs_days    = 10
max_binlog_size         = 100M
[mysqldump]
quick
quote-names
max_allowed_packet  = 16M
[mysql]
[isamchk]
key_buffer      = 16M
!includedir /etc/mysql/conf.d/

我嘗試將bind-address上面的行更改為0.0.0.0,127.0.0.0127.0.1.1(這是因為我在哪裡有127.0.1.1 foo一行是我的 VM 的主機名),這是我網路上機器的實際內部 IP。他們都沒有任何區別。我還嘗試註釋掉這條線以獲得良好的衡量標準和同上。/etc/hosts``foo``10.1.1.213``bind-address

我的系統詳情:

$ cat /etc/issue
Ubuntu 14.04.1 LTS \n \l

$ dpkg -s mysql-server | grep version
Version: 5.5.38-0ubuntu0.14.04.1

這個問題確實與apparmor有關。出於某種原因,這兩行在新/etc/apparmor.d/usr.sbin.mysql文件中被註釋掉了:

#  /var/lib/mysql/ r,  
#  /var/lib/mysql/** rwk,

取消註釋他們解決了這個問題。感謝@Belrog@slm,他們為我指明了正確的方向。

引用自:https://unix.stackexchange.com/questions/158694