萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> mysql 修改目錄後mysqld啟動報錯

mysql 修改目錄後mysqld啟動報錯

mysql 修改目錄後mysqld啟動報錯問題小編也碰到過修改了data目錄發現啟動失敗了,那麼碰到此問題要如何處理,我們下面來看看。


在一台ubuntu測試機器上啟動一個mysql實例,本來應該是一件很簡單的事情,啟動的時候卻報錯了:

mysqld_safe --defaults-file=/etc/mysql/my3307.cnf
160218 15:45:13 mysqld_safe Can't log to error log and syslog at the same time.  Remove all --log-error configuration options for --syslog to take effect.
160218 15:45:13 mysqld_safe Logging to '/var/log/mysql/error3307.log'.
160218 15:45:13 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql3307
160218 15:45:15 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld3307.pid ended
查看錯誤日志/var/log/mysql/error3307.log

發現是由於權限問題無法創建ibdata文件:
 

160218 12:19:09 InnoDB: Completed initialization of buffer pool
160218 12:19:09  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'create'.
InnoDB: Cannot continue operation.

查看目錄,理論上應該有讀寫權限的啊:

ls -ld /var/lib/mysql3307 drwx—— 4 mysql mysql 4096 Feb 18 15:09 /var/lib/mysql3307

難道還有其它什麼權限限制?

用dmesg看一下,確實有一些報錯,

[4489099.208660] type=1400 audit(1455768562.142:57): apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/var/lib/mysql3307/ibdata1" pid=19775 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=105 ouid=105

查看/usr/sbin/mysqld的配置:

vi /etc/apparmor.d/usr.sbin.mysqld

增加mysql3307目錄的權限,重啟apparmor:

 /var/lib/mysql3307/ r,
 /var/lib/mysql3307/** rwk,
/etc/init.d/apparmor restart

再次重新啟動mysqld,發現還是報錯,不過這次報錯的信息不一樣了:

160218 12:44:03 [ERROR] Can't start server : Bind on unix socket: Permission denied
160218 12:44:03 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld3307.sock ?
160218 12:44:03 [ERROR] Aborting

dmesg也能看到錯誤消息:

[4491181.040673] type=1400 audit(1455770643.975:99): apparmor=”DENIED” operation=”mknod” profile=”/usr/sbin/mysqld” name=”/run/mysqld/mysqld3307.sock” pid=24093 comm=”mysqld” requested_mask=”c” denied_mask=”c” fsuid=105 ouid=105
到/etc/apparmor.d/usr.sbin.mysqld增加配置,重啟apparmor
 /var/run/mysqld/mysqld3307.pid rw,
 /var/run/mysqld/mysqld3307.sock w,
 /run/mysqld/mysqld3307.pid rw,
 /run/mysqld/mysqld3307.sock w,

再次重啟mysqld,還是報錯,不過這次是新的報錯:

160218 12:57:27 [Note] Server socket created on IP: '0.0.0.0'.
160218 12:57:27 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
160218 12:57:27 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld3307.pid ended
跑一下mysql_install_db –defaults-file=/etc/mysql/my3307.cnf
這次mysqld終於可以正常啟動了:
160218 14:44:59 [Note] Server socket created on IP: '0.0.0.0'.
160218 14:44:59 [Note] Event Scheduler: Loaded 0 events
160218 14:44:59 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.46-0ubuntu0.14.04.2'  socket: '/var/run/mysqld/mysqld3307.sock'  port: 3307  (Ubuntu)

copyright © 萬盛學電腦網 all rights reserved