mysql 绕过密码登陆

17次阅读
没有评论

前提

  • mysql已安装完好
  • 知道mysql安装目录

操作

# 状况
[root@webra-centos ~]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

# 停止服务
[root@webra-centos bin]# systemctl stop mysqld

# 以安全模式启动MySQL(跳过权限验证)
[root@webra-centos bin]# mysqld_safe --skip-grant-tables &
[1] 556473

# 登陆修改密码
[root@webra-centos bin]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, 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> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxxx';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> exit;
Bye

# 启动服务
[root@webra-centos bin]# systemctl restart mysqld

# 尝试输入密码完成
[root@webra-centos bin]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, 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.
正文完
 0
评论(没有评论)