Centos7安装 mariadb启动错误解决

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7安装 mariadb启动错误解决相关的知识,希望对你有一定的参考价值。

参考技术A 本人遇到mariadb 启动错误的故障解决过程分享。

故障现象 :

Centos7 使用 yum -y install mariadb mariadb-server  安装完成mariadb后启动错误。

错误信息:

[root@iZ882mt6umfZ ~]# systemctl status mariadb.service

[0m mariadb.service - MariaDB database server

Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)

Active: failed (Result: exit-code) since Fri 2019-03-01 09:25:54 CST; 9s ago

Process: 309 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=1/FAILURE)

Process: 308 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)

Process: 32745 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)

Main PID: 308 (code=exited, status=0/SUCCESS)

Mar 01 09:25:53 iZ882mt6umfZ systemd[1]: Starting MariaDB database server...

Mar 01 09:25:53 iZ882mt6umfZ mariadb-prepare-db-dir[32745]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.

Mar 01 09:25:53 iZ882mt6umfZ mariadb-prepare-db-dir[32745]: If this is not the case, make sure the /var/lib/mysql is empty before running mariad...db-dir.

Mar 01 09:25:53 iZ882mt6umfZ mysqld_safe[308]: 190301 09:25:53 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.

Mar 01 09:25:53 iZ882mt6umfZ mysqld_safe[308]: 190301 09:25:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

Mar 01 09:25:54 iZ882mt6umfZ systemd[1]: mariadb.service: control process exited, code=exited status=1

Mar 01 09:25:54 iZ882mt6umfZ systemd[1]: Failed to start MariaDB database server.

Mar 01 09:25:54 iZ882mt6umfZ systemd[1]: Unit mariadb.service entered failed state.

Mar 01 09:25:54 iZ882mt6umfZ systemd[1]: mariadb.service failed.

解决方案:

yum install mariadb*

chown -R mysql:mysql /var/lib/mysql/

启动正常:

root@iZ882mt6umfZ ~]# systemctl start mariadb

[root@iZ882mt6umfZ ~]# systemctl status mariadb

[0m mariadb.service - MariaDB database server

Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)

Active: active (running) since Fri 2019-03-01 09:38:58 CST; 13s ago

Process: 1875 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)

Process: 1843 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)

Main PID: 1874 (mysqld_safe)

CentOS7安装mysql后无法启动服务,提示Unit not found

CentOS7安装mysql后无法启动服务,提示Unit not found

 

1、最近在centos7上面进行mysql安装完成后,无法启动,报如下错误:

Failed to start mysql.server.service: Unit not found.

2、这个是知乎上面找到的无法启动的答案:https://www.zhihu.com/question/41832866

3、解决办法一:使用MariaDB代替mysql数据库(MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。)

# yum install mariadb-server -y //如果已安装可以省略
# systemctl start mariadb.service //启动服务
# systemctl enable mariadb.service //开机启动服务
# mysql -u root -p //登录mysql

  解决办法二:这个方法就是在 /etc/systemd/system/mysqld.service 添加Unit,既然错误提示找不到Unit那我们添加一个就好了。在 /etc/systemd/system/mysqld.service下添加如下内容

复制代码
[Unit]
Description=MySQL Server
After=network.target
 
[Service]
ExecStart=/usr/bin/mysqld --defaults-file=/etc/mysql/my.cnf --datadir=/var/lib/mysql --socket=/var/run/mysqld/mysqld.sock User=mysql
Group=mysql
WorkingDirectory=/usr
 
[Install]
WantedBy=multi-user.target
复制代码

然后运行

systemctl daemon-reload
使用重启命令:

systemctl start mysql.service

以上是关于Centos7安装 mariadb启动错误解决的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7安装mysql后无法启动服务,提示Unit not found

CentOS7安装mysql后无法启动服务,提示Unit not found

centos7安装mariadb出现依赖问题的解决

centos7安装mariadb10遇到的问题解决

当 my.cnf 中的 innodb 未注释时,MariaDB 列存储未启动

CentOS7.3yum安装MariaDB报错[Errno 256]