MySql教程

[mysql] 记测试环境mariadb启动失败

本文主要是介绍[mysql] 记测试环境mariadb启动失败,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

背景

需要配置VM的硬件信息,故重启了VM,结果开机后mariadb启动失败:

# systemctl restart mariadb
Authorization not available. Check if polkit service is running or see debug message for more information.
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.

分析

按提示查看服务status

执行systemctl status mariadb.service查看:

● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-12-08 09:38:23 CST; 2min 23s ago
  Process: 14882 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 14846 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 14881 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─14881 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─15070 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/log/mariadb/mariadb.pid --sock...

Dec 08 09:38:21 vm systemd[1]: Starting MariaDB database server...
Dec 08 09:38:21 vm mariadb-prepare-db-dir[14846]: Failed to get D-Bus connection: Permission denied
Dec 08 09:38:21 vm mariadb-prepare-db-dir[14846]: Failed to get D-Bus connection: Permission denied
Dec 08 09:38:21 vm mariadb-prepare-db-dir[14846]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
Dec 08 09:38:21 vm mariadb-prepare-db-dir[14846]: If this is not the case, make sure the /var/lib/mysql is empty before running mariadb-prepare-db-dir.
Dec 08 09:38:21 vm mysqld_safe[14881]: 211208 09:38:21 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Dec 08 09:38:21 vm mysqld_safe[14881]: 211208 09:38:21 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Dec 08 09:38:23 vm systemd[1]: Started MariaDB database server.

查看log文件

大致是因为某个权限问题,但上面看不出来,只能再查看log文件vi /var/log/mariadb/mariadb.log,发现关键信息:

...
211208  8:36:26 [ERROR] mysqld: Can't create/write to file '/var/run/mariadb/mariadb.pid' (Errcode: 13)
211208  8:36:26 [ERROR] Can't start server: can't create PID file: Permission denied
211208 08:36:26 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
...

检查权限

以上说明文件/var/run/mariadb/mariadb.pid无法被创建和写入,经过一些检查,发现其他用户无权限对/var/run目录进行:

# cd /var
# ll
...
drwx------. 12 root root  256 Dec  8 09:43 run
...

一般来说,我们一般不会使用root去启动mysql相关的服务,在部署的时候会独立创建一些mysql的用户和用户组,用mysql这个用户专职启动mysql服务;

解决方法

#chmod -R 755 /var/run
# cd /var
#ll
...
drwxr-xr-x. 12 root root  256 Dec  8 09:43 run
...
这篇关于[mysql] 记测试环境mariadb启动失败的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!