mysql root 用户 grant 报错

一台mysql数据,使用root用户登录,-h指定的127.0.0.1,执行grant操作时报错:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

检查root用户权限,已经有了super和grant权限了:

mysql> SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user where user = 'root' \G;
*************************** 1. row ***************************
      host: 127.0.0.1
      user: root
  password: *66EF9***************************
Grant_priv: Y
Super_priv: Y
*************************** 2. row ***************************
      host: localhost
      user: root
  password: *66EF9***************************
Grant_priv: Y
Super_priv: Y

找了半天原因,排除了本机host,连接方式以及user表中host列为%的干扰,始终无法授权新用户,见了鬼了。
后来有说是因为数据库升级导致的,但是这个mysql并没有升级,版本一直为5.5
最后还是按照升级后出现无法grant的解决办法,执行了如下操作:

# mysql_upgrade -h127.0.0.1 -uroot -p'mypasswd'
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
mysql.Ghost                                        OK
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.ertyui                                       OK
mysql.event                                        OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.host                                         OK
mysql.myhexc                                       OK
mysql.ndb_binlog_index                             OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.servers                                      OK
mysql.slow_log                                     OK
mysql.tables_priv                                  OK
mysql.tempEx                                       OK
mysql.tempExT                                      OK
mysql.tempExT1                                     OK
mysql.tempMix1                                     OK
mysql.time_zone                                    OK
OK
。。。

现在再执行grant操作,发现可以了,特此记录一下。

u2

Related Posts

mysql连接失败:The driver has not received any packets from the server

解决java spring连接mysql报错问题,增加连接串参数

python cx-Oracle 驱动安装

安装oracle驱动 cx-Oracle驱动二进制版本下载地…

You Missed

Anthropic 推出 Claude Code Security:AI 驱动的代码安全神器

  • u2
  • 2月 24, 2026
  • 11 views

来自 OWASP 的代码安全检查工具:Dependency-Check,为你消除安全隐患

  • u2
  • 10月 16, 2025
  • 1 views
来自 OWASP 的代码安全检查工具:Dependency-Check,为你消除安全隐患

技术宅如何躲开越来越垃圾的CSDN?

  • u2
  • 4月 11, 2024
  • 0 views
技术宅如何躲开越来越垃圾的CSDN?

mysql连接失败:The driver has not received any packets from the server

  • u2
  • 3月 26, 2024
  • 1 views
mysql连接失败:The driver has not received any packets from the server

几个IT小哥常用的工具挂图

  • u2
  • 3月 22, 2024
  • 1 views

好用的代码库密钥泄露检测工具:gitleaks

  • u2
  • 3月 20, 2024
  • 0 views