Linux

無法以普通使用者身份啟動 MySQL 5.5 (fedora 15)

  • September 13, 2011

service mysqld start給我:

Starting mysqld (via systemctl):  Job failed. See system logs and 'systemctl status' for details.
                                                          [FAILED]

錯誤日誌說:

110913 05:50:44 mysqld_safe Starting mysqld daemon with databases from /home/mysql/prod
110913  5:50:44 [Warning] Can't create test file /home/mysql/prod/myhostname.lower-test
110913  5:50:44 [Warning] Can't create test file /home/mysql/prod/myhostname.lower-test
110913  5:50:44 [Note] Plugin 'FEDERATED' is disabled.
110913  5:50:44 InnoDB: The InnoDB memory heap is disabled
110913  5:50:44 InnoDB: Mutexes and rw_locks use GCC atomic builtins
110913  5:50:44 InnoDB: Compressed tables use zlib 1.2.5
110913  5:50:44 InnoDB: Using Linux native AIO
110913  5:50:44 InnoDB: Initializing buffer pool, size = 16.0M
110913  5:50:44 InnoDB: Completed initialization of buffer pool
110913  5:50:44  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 /home/mysql/prod/ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
110913 05:50:44 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

哦,錯誤 13,所以這是一個權限問題,對吧?

chown -R mysql:mysql /home/mysql/prod

仍然不會開始……讓我們試試這個:

/usr/libexec/mysqld --console --log-warnings --basedir=/usr --datadir=/home/mysql/prod --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock

好的,這樣開始就好了(我可以使用 登錄mysql -u root -p),但我什至不知道這是在做什麼,它肯定不是由 systemctl 管理的。讓我們確保 mysql 是一個使用者:

# grep 'mysql' /etc/passwd
mysql:stuff:stuff:MySQL Server:/var/lib/mysql:/bin/bash

我的 my.cnf,有點縮寫(我已經嘗試了下面的很多變體):

[client]
#password       = your_password
port            = 3306
socket         = /var/lib/mysql/mysql.sock

[mysqld]
user            = mysql
port            = 3306
basedir         = /usr
log_warnings    = 1
datadir         = /home/mysql/prod
socket          = /var/lib/mysql/mysql.sock
log-error       = /var/log/mysql.log


innodb_data_home_dir = /home/mysql/prod
innodb_data_file_path = ibdata1:10M:autoextend
#innodb_doublewrite = on
#innodb_log_group_home_dir = /home/mysql/prod

我在這裡有點不知所措..有人可以給我留言嗎?

# ls -lah / | grep 'home'
drwxr-xr-x.   6 root root 4.0K Aug 15 12:20 home
# ls -lah /home | grep 'mysql'
drwxr-xr-x.  6 mysql    mysql    4.0K Sep  8 06:14 mysql
# ls -lah /home/mysql/prod
drwxr-x---.  2 mysql mysql 4.0K Sep 14  2009 bugs
-rw-r--r--.  1 mysql mysql  18M Sep 13 06:17 ibdata1
-rw-r--r--.  1 mysql mysql 5.0M Sep 13 06:17 ib_logfile0
-rw-r--r--.  1 mysql mysql 5.0M Sep 13 05:23 ib_logfile1

(出於隱私考慮,刪除了上面的一些內容)

如果您使用的是 SELinux(Fedora、SUSE、一些 Ubuntu),則可能是問題所在。您需要使用以下內容更改 mySQL 的安全上下文:

chcon -Rv --type=mysqld_db_t /my/new/data/dir

或者如果您使用的是 AppArmor (Ubuntu),則需要更新您的

/etc/apparmor.d/usr.sbin.mysql

引用自:https://serverfault.com/questions/310904