Fedora 中启动 Mysql/Mariadb 失败

Fedora 中启动 Mysql/Mariadb 失败

无法在 Fedora 17 中启动 mysql。我使用root帐户运行以下命令,并且 selinux 被禁用。

service mysqld start
Redirecting to /bin/systemctl start  mysqld.service
Job for mariadb.service failed. See 'systemctl status mariadb.service' and 'journalctl -xn' for details.

systemctl status mariadb.service
mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled)
   Active: failed (Result: exit-code) since Tue 2014-09-23 11:29:32 SGT; 10s ago
  Process: 4251 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=1/FAILURE)
  Process: 4250 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=1/FAILURE)
  Process: 4222 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 4250 (code=exited, status=1/FAILURE)

Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: 140923 11:29:32 mysqld_safe WSREP: Running position recovery with --log_error='/var/...er.pid'
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: /usr/bin/mysqld_safe: line 138: /var/log/mariadb/mariadb.log: Permission denied
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: /usr/bin/mysqld_safe: line 182: /var/log/mariadb/mariadb.log: Permission denied
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: 140923 11:29:32 mysqld_safe WSREP: Failed to recover position:
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: ''
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: /usr/bin/mysqld_safe: line 138: /var/log/mariadb/mariadb.log: Permission denied
Sep 23 11:29:32 acer-4930g systemd[1]: mariadb.service: main process exited, code=exited, status=1/FAILURE
Sep 23 11:29:32 acer-4930g systemd[1]: mariadb.service: control process exited, code=exited status=1
Sep 23 11:29:32 acer-4930g systemd[1]: Failed to start MariaDB database server.
Sep 23 11:29:32 acer-4930g systemd[1]: Unit mariadb.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.

journalctl -xn
-- Logs begin at Sat 2014-04-26 15:18:22 SGT, end at Tue 2014-09-23 11:29:34 SGT. --
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: /usr/bin/mysqld_safe: line 138: /var/log/mariadb/mariadb.log: Permission denied
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: /usr/bin/mysqld_safe: line 182: /var/log/mariadb/mariadb.log: Permission denied
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: 140923 11:29:32 mysqld_safe WSREP: Failed to recover position:
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: ''
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: /usr/bin/mysqld_safe: line 138: /var/log/mariadb/mariadb.log: Permission denied
Sep 23 11:29:32 acer-4930g systemd[1]: mariadb.service: main process exited, code=exited, status=1/FAILURE
Sep 23 11:29:32 acer-4930g systemd[1]: mariadb.service: control process exited, code=exited status=1
Sep 23 11:29:32 acer-4930g systemd[1]: Failed to start MariaDB database server.
-- Subject: Unit mariadb.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mariadb.service has failed.
-- 
-- The result is failed.
Sep 23 11:29:32 acer-4930g systemd[1]: Unit mariadb.service entered failed state.
Sep 23 11:29:34 acer-4930g PackageKit[4204]: daemon quit

getenforce 
Permissive

然后我将 mariadb 日志文件的所有权从 更改为rootmysql仍然失败:

[root@acer-4930g ~]# ls -ld /var/log/mariadb/
drwxr-x---. 2 mysql mysql 4096 Sep 23 11:02 /var/log/mariadb/
[root@acer-4930g ~]# ls -l /var/log/mariadb/mariadb.log 
-rw-rw----. 1 root root 554 Sep 23 11:02 /var/log/mariadb/mariadb.log
[root@acer-4930g ~]# chown -R mysql:mysql /var/log/mariadb -chR
[root@acer-4930g ~]# systemctl restart mariadb.service 
Job for mariadb.service failed. See 'systemctl status mariadb.service' and 'journalctl -xn' for details.

[root@acer-4930g ~]# systemctl status mariadb.service 
mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled)
   Active: failed (Result: exit-code) since Tue 2014-09-23 14:58:09 SGT; 3min 4s ago
  Process: 6890 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=1/FAILURE)
  Process: 6889 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=1/FAILURE)
  Process: 6861 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 6889 (code=exited, status=1/FAILURE)

Sep 23 14:58:09 acer-4930g mysqld_safe[6889]: 140923 14:58:08 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade ...ate it.
Sep 23 14:58:09 acer-4930g mysqld_safe[6889]: 140923 14:58:08 [ERROR] Aria engine is not enabled or did not start. The Aria engine...-tables
Sep 23 14:58:09 acer-4930g mysqld_safe[6889]: 140923 14:58:08 [ERROR] Aborting
Sep 23 14:58:09 acer-4930g mysqld_safe[6889]: 140923 14:58:08  InnoDB: Starting shutdown...
Sep 23 14:58:09 acer-4930g mysqld_safe[6889]: 140923 14:58:09  InnoDB: Shutdown completed; log sequence number 1597945
Sep 23 14:58:09 acer-4930g mysqld_safe[6889]: 140923 14:58:09 [Note] /usr/libexec/mysqld: Shutdown complete'
Sep 23 14:58:09 acer-4930g systemd[1]: mariadb.service: main process exited, code=exited, status=1/FAILURE
Sep 23 14:58:09 acer-4930g systemd[1]: mariadb.service: control process exited, code=exited status=1
Sep 23 14:58:09 acer-4930g systemd[1]: Failed to start MariaDB database server.
Sep 23 14:58:09 acer-4930g systemd[1]: Unit mariadb.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.

答案1

权限?

您正在显示该命令,service mysqld start但您是否在该命令前面添加了前缀sudo?我怀疑您没有启动此服务的权限,因为您在 Q 中包含的输出中收到了这些“权限被拒绝的消息”。

Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: /usr/bin/mysqld_safe: line 138: /var/log/mariadb/mariadb.log: Permission denied
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: /usr/bin/mysqld_safe: line 182: /var/log/mariadb/mariadb.log: Permission denied
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: 140923 11:29:32 mysqld_safe WSREP: Failed to recover position:
Sep 23 11:29:32 acer-4930g mysqld_safe[4250]: ''

如果您实际上正在使用,sudo那么我会将注意力转移到上面日志消息中提到的目录和文件。关注这个目录/文件:

$ ls -ld /var/log/mariadb
$ ls -l /var/log/mariadb/mariadb.log

我在 AskFedora 问答中找到了这些命令,标题为:mariadb 服务未启动:权限被拒绝,这应该可以解决您的问题:

$ sudo chown mysql:mysql /var/log/mariadb -chR

其次是:

$ sudo systemctl restart mariadb.service && \
    sudo systemctl status mariadb.service

看来 MariaDB 日志文件不允许用户mysql访问它们,上述命令将解决此问题。

数据库损坏?

如果您仍然遇到问题并遇到以下错误:

Sep 23 14:58:09 acer-4930g mysqld_safe[6889]: 140923 14:58:08 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade ...ate it.

您现在还可以确认上述权限问题已解决,在 MariaDB 日志文件中的消息如下:

Version check failed. Got the following error when calling the 'mysql' command line client
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
FATAL ERROR: Upgrade failed

任一消息基本上都告诉您在将 MySQL 数据库升级到 Maria 数据库时出现问题。如果它是一个数据库,其中没有您关心的内容,您只需移动它或删除它即可。这将要求您首先删除 MariaDB 软件包,然后重新安装它。

例子

$ sudo yum remove mariadb-server

### To remove
$ sudo rm -rf /usr/lib/mysql

### To move
$ sudo mv /usr/lib/mysql /usr/lib/mysql.orig

$ sudo yum install mariadb-server

笔记:上述提示的来源:启动 mariadb 服务时遇到问题

上述提示中我无法确认的一件事是要移动/删除的目录是否为/usr/lib/mysql.或者/var/lib/mysql。我不确定该提示中是否有拼写错误。因此,我会首先执行上述操作/usr/lib/mysql,如果不起作用,则重复这些步骤,但使用/var/lib/mysql.我会首先使用删除方法,如果一切正常,然后返回并删除损坏的目录。

笔记: /var/lib/mysql是数据库文件所在的位置,/usr/lib/mysql目录是各种插件所在的位置。

相关内容