Failed to start mysqld.service: Unit not found问题解决方案

1.首先安装mariadb-server
yum install -y mariadb-server
2.启动服务
systemctl start mariadb.service
3.添加到开机启动
systemctl enable mariadb.service
4.安全设置,修改数据库管理员密码
[root@js opt]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):

什么都不用输入,直接回车。

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
(py3) [root@js opt]# mysql -uroot -paisino
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql;
ERROR 1049 (42000): Unknown database 'mysql;'
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> select  User,authentication_string,Host from user;
    -> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that                                                                                         corresponds to your MariaDB server version for the right syntax to use near 'GRA                                                                                        NT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456'' at line 2
MariaDB [mysql]> select  User,authentication_string,Host from user; GRANT ALL P                                                                                        RIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'aisino';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that                                                                                         corresponds to your MariaDB server version for the right syntax to use near 'GRA                                                                                        NT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'aisino'' at line 1
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.01 sec)

MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'aisino                                                                                        ';
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]>

root开启远程访问权限

use mysql;
select  User,authentication_string,Host from user;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
flush privileges;
  • 7
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当你遇到 "Failed to start mysqld.service: Unit not found." 这样的错误时,通常表示系统找不到名为 `mysqld.service` 的服务单元。这可能是由于以下原因: 1. **服务未安装**:确认MySQL是否已经正确安装并配置过。如果是新安装的MySQL,确保安装过程完整,并检查 `/etc/systemd/system/mysqld.service` 文件是否存在。 2. **启动文件路径错误**:确认`mysqld.service` 的位置是否正确,如果是在其他目录下,需要更新 systemd 的默认搜索路径。 3. **服务未启用**:运行 `systemctl status mysql` 或 `systemctl status mysqld` 检查服务状态,如果不是active(running),尝试手动启用它:`sudo systemctl enable mysqld`. 4. **权限问题**:执行命令时可能需要 root 权限,可以试着加上 `sudo`:`sudo systemctl start mysqld`. 5. **服务文件损坏**:检查 `mysqld.service` 文件是否有语法错误,可以备份原文件后尝试修复或替换。 6. **依赖问题**:确认MySQL是否有必要的依赖项(如network.target、multilib.target等),如果没有,安装它们。 7. **更新系统或MySQL后遗症**:有时候系统升级或MySQL版本变更可能导致服务文件配置冲突,检查是否有相关更新日志或解决方案。 解决这个问题后,你可以通过 `sudo systemctl start mysqld` 启动服务,然后查看其运行状态确认是否正常。如果还是有问题,记得记录每个步骤以便排查。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值