mysql5.7 报错:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

21 篇文章 1 订阅

1.在cenos7上用yum安装mysql 5.7
1)配置mysql的yum

[root@centos7 ~]#tee /etc/yum.repos.d/mysql.repo << EOF
[mysql]
name=mysql5.7
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/
gpgcheck=0
EOF

2.安装Mysql

yum -y install mysql-community-server

3.启动mysql

systemctl enable --now mysqld

4.查看端口 已经启动

[root@centos7 ~]#systemctl start mysqld
[root@centos7 ~]#ss -ntl
State      Recv-Q Send-Q Local Address:Port                Peer Address:Port              
LISTEN     0      128                *:22                             *:*                  
LISTEN     0      80                :::3306                          :::*                  
LISTEN     0      128               :::22                            :::*     

5.执行mysql 不能实现免密登录

[root@centos7 ~]#mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决:

Mysql 5.7 为了安全,使用的随机密码 ,登录的时候就得需要账号密码

1)找到密码

[root@centos7 ~]#grep password /var/log/mysqld.log 
2021-05-13T00:02:05.229162Z 1 [Note] A temporary password is generated for root@localhost: fw?O6v/tkme(
2021-05-13T00:02:14.264808Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)

2)通过账号密码登录 (这个密码要用单引号引起来,因为它随机密码是带的特殊符号)

[root@centos7 ~]#mysql -uroot -pfw?O6v/tkme(
-bash: syntax error near unexpected token `(' '`
[root@centos7 ~]#mysql -uroot -p'fw?O6v/tkme('
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.34

Copyright (c) 2000, 2021, 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> 

3)查看状态的时候,发现它要求立即修改密码

mysql> status
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

在这里插入图片描述
4)不会可以查看帮助
在这里插入图片描述
自己及其不能看只能通过别的机器查询

4)修改密码
设密码太简单是不行的-------------大小写字母+数字+特殊符号(这个可行)

mysql> alter user root@'localhost' identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

mysql> alter user root@'localhost' identified by 'MyNewPass4!';
Query OK, 0 rows affected (0.00 sec)

5)退出再次登录

[root@centos7 ~]#mysql -uroot -p'MyNewPass4!'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> 

6)再次查看状态就可以了

mysql> status
--------------
mysql  Ver 14.14 Distrib 5.7.34, for Linux (x86_64) using  EditLine wrapper

Connection id:		4
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		5.7.34 MySQL Community Server (GPL)
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	latin1
Db     characterset:	latin1
Client characterset:	utf8
Conn.  characterset:	utf8
UNIX socket:		/var/lib/mysql/mysql.sock
Uptime:			23 min 7 sec

Threads: 1  Questions: 11  Slow queries: 0  Opens: 106  Flush tables: 1  Open tables: 99  Queries per second avg: 0.007

7)发现5.7 不允许匿名登录

[root@centos7 ~]#mysql -uxxx -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'xxx'@'localhost' (using password: YES)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值