MySQL问题解决记录:ERROR 1045 (28000): Access denied for user ‘ODBC‘@‘localhost‘ (using password: YES/NO)


系统:Windows11
MySQL:官网下载的压缩包版本
工具:管理员权限下的CMD(始终)
核心问题:↓

> mysql --version
mysql  Ver 8.4.0 for Win64 on x86_64 (MySQL Community Server - GPL)
> mysql
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
> mysql -uroot -p123456
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

情况一:密码错误?

> mysql -uroot -p"awjiofgpak"(随便写出错误密码)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  • 故意输错密码同样报该错误(能正常使用正确密码登录的同学的设备中输错密码也同为该错误),因此不能排除密码错误的可能性。
  • 接下来进入–skip-grant-tables模式检验:
进入–skip-grant-tables模式方法一(MySQL8.0版本之前):

在my.ini文件的[mysqld]底下加一句skip-grant-tables);

  • 可能出现报错:ERROR 2003 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)
  • 可能出现异常:net start mysql执行失败,mysql服务仍未打开。
  • 原因:在my.ini中加入skip-grant-tables在mysql8.0中已失效。Mysql 8.X的方法是在命令行中使用mysqld --console --skip-grant-tables --shared-memory启动服务器然后root就可以免密登录了(需要开2个CMD窗口)。
    @内容来自:https://blog.csdn.net/q283614346/article/details/90732968
进入–skip-grant-tables模式方法二(MySQL8.0版本之后):
> net stop mysql
> mysqld --console --skip-grant-tables --shared-memory
  • (使用管理员权限新开一个CMD窗口)

  • 关于–skip-grant-tables模式下的mysql数据库的user表中的密码字段,老版本为"password",新版本为"authentication_string"
    @参考文章:https://blog.csdn.net/zww1984774346/article/details/95948120Mysql报错“Unknown Column 'Password' In Field List”解决办法

  • 若密码字段为"password",则查询密码的语句为select user,password,host from user where user="root";

  • 若密码字段为"authentication_string",则查询密码的语句为select user,passauthentication_stringword,host from user where user="root";

查询密码错误情况:
  • 若之前输入的密码不同于查询到的密码,可选择重置密码:ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
  • 结合密码错误时的确报错ERROR 1045 (28000),暂推断该情况解决。

@内容来自:https://blog.csdn.net/dxy1128/article/details/116043330
在这里插入图片描述


  • 更改密码错误语句写法:set password for root@localhost = password(123456);
  • 该错误写法可能出错:
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 ‘password(‘123456’)’ at line 1

@内容来自:https://blog.csdn.net/qq_41550190/article/details/117961690
在这里插入图片描述


  • 更改密码正确语句:ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';可能出错:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
  • 即在当前–skip-grant-tables模式下没有足够权限执行更改密码。
  • 解决方案:置空密码,见文章情况六。
查询密码异常情况:
> mysql
mysql> use mysql
Database changed
mysql> select user,host,password from user where user='root';
+——+——————-+——————————————-+
| user | host | password |
+——+——————-+——————————————-+
| root | % | *A50E066E106320CF4142 |
| root | centos | *A50E066E106320CF4142 |
| root | 127.0.0.1 | *A50E066E1063608320CF4142 |
+——+——————-+——————————————-+
3 rows in set (0.12 sec)

解决方案:

mysql> update user set host='localhost' where user='root' and host='%';
mysql> flush privileges;

@内容来自:https://www.cnblogs.com/bchjazh/articles/5851839.html
在这里插入图片描述


查询密码正常情况:
> mysql
mysql> use mysql;
Database changed
mysql> select user,authentication_string,host from user where user="root";
+------+-----------------------+-----------+
| user | authentication_string | host      |
+------+-----------------------+-----------+
| root | 123456                | localhost |
+------+-----------------------+-----------+
1 row in set (0.00 sec)
  • 查询到的密码与报错ERROR 1045 (28000)前输入的密码相同,排除密码相关的报错原因。

情况二:my.ini配置文件错误?

  • 我当前的my.ini内容:
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[mysqld]
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir="D:/_Envar/Mysql/mysql-8.4.0-winx64"
# 设置mysql数据库的数据的存放目录
datadir="D:/_Envar/Mysql/mysql-8.4.0-winx64/data"
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
bind-address = 127.0.0.1

@相关文档:https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html

试错:端口参数port改为3307
> net stop mysql
> net start mysql
> mysql
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)
  • 报错不同于ERROR 1045 (28000),推断port参数为3306时无误。
试错:my.ini文件末尾添加随意内容
> net stop mysql
> net start mysql
MySQL 服务正在启动 .
MySQL 服务无法启动。

服务没有报告任何错误。

请键入 NET HELPMSG 3534 以获得更多的帮助。
  • 报错不同于ERROR 1045 (28000),推断my.ini格式无误。
试错:my.ini参数basedir/datadir的格式(去掉双引号)
basedir=D:/_Envar/Mysql/mysql-8.4.0-winx64
datadir=D:/_Envar/Mysql/mysql-8.4.0-winx64/data
> net start mysql
...
> mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  • 仍报错ERROR 1045 (28000),无法推断该格式有效。
试错:my.ini参数basedir/datadir的格式(去掉双引号+反斜杠)
basedir=D:\_Envar\Mysql\mysql-8.4.0-winx64
datadir=D:\_Envar\Mysql\mysql-8.4.0-winx64\data
> net stop mysql
...
> net start mysql
...
> mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  • 仍报错ERROR 1045 (28000),无法推断该格式有效。

情况三:MySQL权限问题?

检查用户权限(?):SELECT user, host FROM mysql.user WHERE user='root';
+------+-----------+
| user | host      |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.00 sec)
  • 确保’root’用户具有从localhost登录的权限。
  • 如果没有,请使用以下命令授予权限:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';
FLUSH PRIVILEGES;`
  • 可能出错:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
  • 即当前使用的–skip-grant-tables模式并不拥有足够的权限来检验该方案。

@内容来自:https://developer.baidu.com/article/details/2856566
在这里插入图片描述


检查用户权限②:SHOW GRANTS FOR 'ODBC'@'localhost';
  • 用户权限的设置也可能是导致访问拒绝的原因。可以检查并设置正确的权限让用户能够连接到服务器:
mysql> SHOW GRANTS FOR 'ODBC'@'localhost';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
  • 如果权限不足,可以使用如下命令赋予权限:
GRANT ALL PRIVILEGES ON *.* TO 'ODBC'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'ODBC'@'localhost' WITH GRANT OPTION;
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
  • 仍报错ERROR 1290 (HY000),即当前使用的–skip-grant-tables模式并不拥有足够的权限来检验该②方案。

@内容来自:https://openatomworkshop.csdn.net/664ee8b9b12a9d168eb71704.html
错误解析
确认用户权限


情况四:MySQL服务相关问题?

  • 在services.msc中查找MySQL的主服务:MySQL(可能是其他名称如MySQL80)
可执行文件路径异常:
  • 进入查看MySQL的属性中的可执行文件的路径
    "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld" MySQL
  • 实际安装的MySQL路径文件夹中的mysqld.exe文件位置:
    "C:\ProgrameData\MySQL\MySQL Server 8.0\mysqld.exe"
  • 错误原因:mysqld.exe 应用程序,在启动的时候,第一时间会去找 一个文件,my.ini,
    这个 my.ini 文件,会告诉 mysqld 需要在启动的时候做些什么,
    所以,我们只要配置好 my.ini 文件,就能告诉和指挥 MySQL 怎么做,也就能达到我们 只使用一个命令 mysql 就能登录到 MySQL 的 控制台里,而不需要 输入 繁琐的 各种参数,
    所以,问题的关键,就在 这个 my.ini 文件上了。
    接下来,就是去找到 my.ini 这个文件了…

@内容来自及后续解决方案:https://blog.csdn.net/m0_47505062/article/details/122342121
在这里插入图片描述


可执行文件路径正常:
  • 进入查看MySQL的属性中的可执行文件的路径
    "D:\_Envar\Mysql\mysql-8.4.0-winx64\bin\mysqld" MySQL
  • 实际安装的MySQL路径文件夹中的mysqld.exe文件位置:
    D:\_Envar\Mysql\mysql-8.4.0-winx64\bin\mysqld.exe
  • 查询到的路径无异常,推断MySQL服务本身正常。

情况五:"ODBC"用户不存在?

  • 首先需要确认用户’ODBC’是否在MySQL数据库中存在。
  • 可以使用root账户或有足够权限的账户登录到MySQL服务器,然后执行以下SQL语句:
    SELECT user, host FROM mysql.user WHERE user='ODBC';
"ODBC"用户存在
  • 待补充。
"ODBC"用户不存在
mysql> SELECT user, host FROM mysql.user WHERE user='ODBC';
Empty set (0.00 sec)
  • 如果查询结果为空,则说明用户不存在。
  • 你需要创建用户或使用存在的用户进行连接。

@内容来自:https://openatomworkshop.csdn.net/664ee8b9b12a9d168eb71704.html
确认用户存在


  • 这是我的情况,详细的解决方案正在查询中。
  • 类似的方法和资料查询无果,暂怀疑该解决方案。

情况六:???(解决方案)

  • 在–skip-grant-tables模式下进入,置空密码:
mysql> use mysql;
mysql> update user set authentication_string='' where user='root';
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> quit;
  • 关闭正在执行mysqld --console --skip-grant-tables --shared-memory 的窗口。
  • 使用空密码登录mysql,此时拥有足够权限执行更改密码语句:
>mysql -uroot -p
Enter password:(回车)
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.04 sec)
mysql> quit;
Bye

@内容来自:https://blog.csdn.net/qq_43342301/article/details/91288891
在这里插入图片描述


  • 再次登录时已无该报错ERROR 1045 (28000),本文章完结:
>mysql
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
>mysql -uroot -p123456
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 12
Server version: 8.4.0 MySQL Community Server - GPL
Copyright (c) 2000, 2024, 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>
  • 原因呢?试错:将密码由’123456’改为"123456":
mysql> alter user 'root'@'localhost' identified by "123456";
Query OK, 0 rows affected (0.04 sec)
mysql> exit;
mysql -uroot -p123456
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 14
Server version: 8.4.0 MySQL Community Server - GPL

Copyright (c) 2000, 2024, 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>
  • 试错失败,未复原错误ERROR 1045 (28000),无法断定原密码的问题。
  • 28
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值