当前位置: 首页 > news >正文

多个 root 用户记录,而且有些记录的密码是空的,导致认证混乱。

多个 root 用户记录,而且有些记录的密码是空的,导致认证混乱。

留言:之前再讲mysql时候,经常有人可以远程登录的时候,结果发现没办法本地登录了,具体体现方式是这样的(看问题体现):现在我可以明确的告诉你们,是你们的root认证太多了,系统无法识别你要的是哪一个root,干脆只给你一个匿名用户,会出现什么现象呢,就是你直接mysql -uroot登进去了(你会惊奇的发现你没输入密码就稀里糊涂的进来了),但你没有任何增删改的权限,不过你可以看看,非常的有意思

问题体现

[root@bogon ~]# mysql -uroot -p123456 -hlocalhost
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@bogon ~]# mysql -uroot -p123456 -h127.0.0.1
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@bogon ~]# mysql -uroot -p123456 --protocol=socket
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

登进去看下啊

[root@bogon ~]# systemctl stop mysqld
[root@bogon ~]# mysqld_safe --skip-grant-tables --skip-networking &
[1] 1617
[root@bogon ~]# Logging to '/application/mysql/data/bogon.err'.
250917 20:29:22 mysqld_safe Starting mysqld daemon with databases from /application/mysql/data[root@bogon ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.40 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> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> SELECT host, user, password FROM user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| %         | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| bogon     | root |                                           |
| 127.0.0.1 | root |                                           |
| ::1       | root |                                           |
| localhost |      |                                           |
| bogon     |      |                                           |
+-----------+------+-------------------------------------------+
6 rows in set (0.00 sec)mysql>

清理用户表并统一密码

DELETE FROM user WHERE user = 'root' AND (password = '' OR host != '%');
DELETE FROM user WHERE user = '';
FLUSH PRIVILEGES;

解决过程

[root@bogon ~]# mysql -uroot -p123456 -hlocalhost
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@bogon ~]# mysql -uroot -p123456 -h127.0.0.1
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@bogon ~]# mysql -uroot -p123456 --protocol=socket
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@bogon ~]# systemctl stop mysqld
[root@bogon ~]# mysqld_safe --skip-grant-tables --skip-networking &
[1] 1617
[root@bogon ~]# Logging to '/application/mysql/data/bogon.err'.
250917 20:29:22 mysqld_safe Starting mysqld daemon with databases from /application/mysql/data[root@bogon ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.40 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> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> SELECT host, user, password FROM user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| %         | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| bogon     | root |                                           |
| 127.0.0.1 | root |                                           |
| ::1       | root |                                           |
| localhost |      |                                           |
| bogon     |      |                                           |
+-----------+------+-------------------------------------------+
6 rows in set (0.00 sec)mysql> DELETE FROM user WHERE user = 'root' AND (password = '' OR host != '%');
Query OK, 3 rows affected (0.01 sec)mysql> SELECT USER(), CURRENT_USER();
+--------+----------------+
| USER() | CURRENT_USER() |
+--------+----------------+
| root@  | @              |
+--------+----------------+
1 row in set (0.00 sec)mysql>  SELECT host, user, password FROM user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| %         | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost |      |                                           |
| bogon     |      |                                           |
+-----------+------+-------------------------------------------+
3 rows in set (0.00 sec)mysql> DELETE FROM user WHERE user = '';
Query OK, 2 rows affected (0.01 sec)mysql> SELECT USER(), CURRENT_USER();
+--------+----------------+
| USER() | CURRENT_USER() |
+--------+----------------+
| root@  | @              |
+--------+----------------+
1 row in set (0.00 sec)mysql>  SELECT host, user, password FROM user;
+------+------+-------------------------------------------+
| host | user | password                                  |
+------+------+-------------------------------------------+
| %    | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+------+-------------------------------------------+
1 row in set (0.00 sec)mysql> exit;
Bye
[root@bogon ~]# pkill mysqld
[root@bogon ~]# 250917 20:35:45 mysqld_safe mysqld from pid file /application/mysql/data/bogon.pid ended[1]+  Done                    mysqld_safe --skip-grant-tables --skip-networking
[root@bogon ~]# systemctl start mysqld
[root@bogon ~]# systemctl status mysqld
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)Active: active (running) since Wed 2025-09-17 20:35:59 CST; 7s agoDocs: man:mysqld(8)https://dev.mysql.com/doc/refman/en/using-systemd.htmlMain PID: 1801 (mysqld)Tasks: 21 (limit: 10892)Memory: 436.8MCPU: 595msCGroup: /system.slice/mysqld.service└─1801 /application/mysql/bin/mysqld --defaults-file=/etc/my.cnfSep 17 20:36:00 bogon mysqld[1801]: 2025-09-17 20:36:00 1801 [Note] InnoDB: 128 rollback segment(s) are active.
Sep 17 20:36:00 bogon mysqld[1801]: 2025-09-17 20:36:00 1801 [Note] InnoDB: Waiting for purge to start
Sep 17 20:36:00 bogon mysqld[1801]: 2025-09-17 20:36:00 1801 [Note] InnoDB: 5.6.40 started; log sequence number 1626107
Sep 17 20:36:00 bogon mysqld[1801]: 2025-09-17 20:36:00 1801 [Note] Server hostname (bind-address): '*'; port: 3306
Sep 17 20:36:00 bogon mysqld[1801]: 2025-09-17 20:36:00 1801 [Note] IPv6 is available.
Sep 17 20:36:00 bogon mysqld[1801]: 2025-09-17 20:36:00 1801 [Note]   - '::' resolves to '::';
Sep 17 20:36:00 bogon mysqld[1801]: 2025-09-17 20:36:00 1801 [Note] Server socket created on IP: '::'.
Sep 17 20:36:00 bogon mysqld[1801]: 2025-09-17 20:36:00 1801 [Note] Event Scheduler: Loaded 0 events
Sep 17 20:36:00 bogon mysqld[1801]: 2025-09-17 20:36:00 1801 [Note] /application/mysql/bin/mysqld: ready for connections.
Sep 17 20:36:00 bogon mysqld[1801]: Version: '5.6.40'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server (GPL)
[root@bogon ~]# mysql -uroot -p123456
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 1
Server version: 5.6.40 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)mysql> create database abc_test;
Query OK, 1 row affected (0.00 sec)mysql> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| abc_test           |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)mysql> history | tail -n 20-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'history | tail -n 20' at line 1
mysql> exit
Bye
[root@bogon ~]# history | tail -n 2060  service mysql restart61  systemctl restart mysqld62  vi /etc/my.cnf63  find / -name "mysqld.cnf"64  systemctl status mysqld65  mysql -uroot66  mysql -uroot -p12345667  mysql -v68  mysql -uroot69  mysql -uroot -p123456 -hlocalhost70  mysql -uroot -p123456 -h127.0.0.171  mysql -uroot -p123456 --protocol=socket72  systemctl stop mysqld73  mysqld_safe --skip-grant-tables --skip-networking &74  mysql -u root75  pkill mysqld76  systemctl start mysqld77  systemctl status mysqld78  mysql -uroot -p12345679  history | tail -n 20
[root@bogon ~]#

验证是否会影响到正常的远程登录

http://www.wxhsa.cn/company.asp?id=6940

相关文章:

  • 解题报告-P11670 [USACO25JAN] Cow Checkups S
  • word vba 对 带编号格式的PO单 段落下添加对应的图片
  • 解题报告-P11671 [USACO25JAN] Farmer Johns Favorite Operation S
  • 解码C语言运算符
  • 多进程
  • 93. 递归实现组合型枚举
  • Sort方法学习(伪代码记录)
  • 深入解析:【每日一问】运算放大器与比较器有什么区别?
  • 9.17支配对问题专题总结
  • 记录知识
  • AT_agc058_b [AGC058B] Adjacent Chmax
  • Jenkins CVE-2018-1000600漏洞利用与SSRF攻击分析
  • NOIP 集训日记(学术)
  • linux中mysql如何远程连接
  • 详细介绍:Python:OpenCV 教程——从传统视觉到深度学习:YOLOv8 与 OpenCV DNN 模块协同实现工业缺陷检测
  • 深入解析:PYcharm——pyqt音乐播放器
  • Day02
  • 专题:Python实现贝叶斯线性回归与MCMC采样数据可视化分析2实例|附代码数据
  • 威联通NAS如何导入本地docker镜像
  • 【学习笔记】拉格朗日插值
  • 一种将离散化状态方程映射为并行多处理器计算机的方法
  • 基本数据类型题目
  • 一种基于动作指令交互的动态活体检测技术,提升人脸识别安全性
  • [系统] Windows 已有office版本和visio不兼容的解决方案
  • CF 2127F Hamed and AghaBalaSar
  • AT_agc055_b [AGC055B] ABC Supremacy
  • “Sequential Thinking MCP Server 和codex等AI工具本身任务拆解功能对比
  • 基于错误xsleak 悬空标记 运用css利用帧计数 -- Pure leak ASIS CTF 2025
  • 网易伏羲:当算法遇见社交,解码游戏世界的连接密码
  • 在 CentOS 7 上安装Nginx和配置http代理