root 123 mysql_mysql5.7懒快修改root初始密码二法

这篇博客记录了在MySQL中遇到的权限问题,包括如何通过日志获取临时密码,以及两种尝试修改root密码的方法:直接使用SQL命令和通过skip-grant-tables选项。在过程中遇到了访问被拒绝的问题,但最终成功设置了新的root密码。
摘要由CSDN通过智能技术生成

0、 法1

[root@k8s2 ~]# grep passw /var/log/mysqld.log

2018-12-18T07:33:26.636232Z 1 [Note] A temporary password is

generated for root@localhost: MR3vtgO7#Ckk

2018-12-18T07:34:09.595172Z 2 [Note] Access denied for user

'root'@'localhost' (using password: NO)

2018-12-18T07:34:15.111707Z 3 [Note] Access denied for user

'root'@'localhost' (using password: NO)

2018-12-18T07:34:27.949428Z 0 [Note] Shutting down plugin

'validate_password'

2018-12-18T07:34:29.589294Z 0 [Note] Shutting down plugin

'sha256_password'

2018-12-18T07:34:29.589300Z 0 [Note] Shutting down plugin

'mysql_native_password'

2018-12-18T07:38:34.850635Z 5 [Note] Access denied for user

'root'@'localhost' (using password: NO)

2018-12-18T07:42:07.719535Z 7 [Note] Access denied for user

'root'@'localhost' (using password: NO)

2018-12-18T07:42:12.692652Z 8 [Note] Access denied for user

'root'@'localhost' (using password: YES)

2018-12-18T07:42:26.577215Z 0 [Note] Shutting down plugin

'sha256_password'

2018-12-18T07:42:26.577225Z 0 [Note] Shutting down plugin

'mysql_native_password'

[root@k8s2 ~]#

从上面找到临时密码

mysql -uroot -p******

use mysql

update user set authentication_string = password('root123'),

password_expired = 'N', password_last_changed = now() where user =

'root';

commit;

flush privileges;

1、 法2

echo "skip-grant-tables=1" >> /etc/my.cnf

systemctl restart mysqld

use mysql

update user set authentication_string = password('root123'),

password_expired = 'N', password_last_changed = now() where user =

'root';

commit;

flush privileges;

1.1 、

##屏蔽修改

sed -i

's/skip-grant-tables=1/##skip-grant-tables=1/g' /etc/my.cnf

2、

[root@k8s2 ~]#

[root@k8s2 ~]# systemctl restart mysqld

[root@k8s2 ~]# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost'

(using password: NO)

[root@k8s2 ~]# mysql root

ERROR 1045 (28000): Access denied for user 'root'@'localhost'

(using password: NO)

[root@k8s2 ~]#

[root@k8s2 ~]#

[root@k8s2 ~]# echo "skip-grant-tables=1" >> /etc/my.cnf

[root@k8s2 ~]# systemctl restart mysqld

[root@k8s2 ~]#

[root@k8s2 ~]# mysql -uroot

Welcome to the MySQL monitor. Commands end

with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.24 MySQL Community Server (GPL)

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

rights reserved.

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> exit

Bye

[root@k8s2 ~]#

3、

mysql> 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

mysql> update user set authentication_string =

password('root123'), password_expired = 'N', password_last_changed

= now() where user = 'root';

Query OK, 1 row affected, 1 warning (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 1

mysql> commit;

Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql>

mysql> exit

Bye

[root@k8s2 ~]# mysql -uroot

ERROR 1045 (28000): Access denied for user 'root'@'localhost'

(using password: NO)

[root@k8s2 ~]# mysql -uroot -proot123

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 6

Server version: 5.7.24 MySQL Community Server (GPL)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值