Quantcast
Channel: 回归江南旧梦
Viewing all articles
Browse latest Browse all 65

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

$
0
0

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)





 

Viewing all articles
Browse latest Browse all 65

Trending Articles