无法以普通用户身份启动 MySQL 5.5(fedora 15)

无法以普通用户身份启动 MySQL 5.5(fedora 15)

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

(为保护隐私,删除了上面的一些内容)

答案1

如果您使用的是 SELinux(Fedora、SUSE、某些 Ubuntu),则可能是这个问题。您需要使用以下方法更改 mySQL 的安全上下文:

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

或者如果你正在使用 AppArmor (Ubuntu),你需要更新你的

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

相关内容