CentOS7.9安装Mysql5.7, 解决公钥未安装错误,设置root密码为空

一. 安装过程中的公钥未安装错误

安装命令:

wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
cd /etc/yum.repos.d/
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
yum install mysql-server

错误信息:

mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm 的公钥尚未安装


 失败的软件包是:mysql-community-libs-compat-5.7.37-1.el7.x86_64
 GPG  密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

解决办法:

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

再次安装,成功

yum install mysql-server

二. 设置root 登录密码为空

启动mysql服务端mysqld后,因为没有配置root及密码,启动mysql客户端会出错

systemctl restart mysqld
mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

设置免密登录

vi /etc/my.cnf
#添加跳过密码验证
skip-grant-tables

重启mysql服务

systemctl restart mysqld

设置root登录密码为空

mysql -uroot
mysql> use mysql
mysql> update user set authentication_string='' where user='root';
mysql> quit

关闭免密登录

vi /etc/my.cnf
#注释掉跳过密码验证
#skip-grant-tables

重启mysql服务

systemctl restart mysqld

登录mysql客户端不需要密码, 出现提示输入密码时直接回车:

mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.37

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 

  • 42
    点赞
  • 126
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值