ERROR 1044 (42000): Access denied for user ‘root‘@‘localhost‘

从供应商那边接手一个MySQL数据库(数据库版本为5.7.21 MySQL Community Server (GPL)),在创建账号时遇到了“ERROR 1044 (42000): Access denied for user ‘root‘@‘localhost‘ to database xxx”错误,如下所示

mysql> grant all on xxx.* to [email protected]‘192.168.%‘ identified by ‘xxx‘;
ERROR 1044 (42000): Access denied for user ‘root‘@‘localhost‘ to database ‘xxxx‘

mysql> 

照理说,root用户应该有任何权限,那么为什么出现这个错误呢? 查看当前用户为[email protected],顺便查看了一下各个root账号的权限。如下所示:

mysql> select current_user() from dual;
+----------------+

| current_user() |

+----------------+

| [email protected] |

+----------------+

1 row in set (0.00 sec

 

mysql> select host,user from user where user=‘root‘;

+-----------+----------+

| host      | user     |

+-----------+----------+

| %         | root     |

| 127.0.0.1 | root     |

| ::1       | root     |

| localhost | root     |

+-----------+----------+

7 rows in set (0.00 sec)

 

mysql>  show grants for [email protected]‘localhost‘;

+--------------------------------------------------------------+

| Grants for [email protected]                                    |

+--------------------------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘localhost‘            |

| GRANT PROXY ON ‘‘@‘‘ TO ‘root‘@‘localhost‘ WITH GRANT OPTION |

+--------------------------------------------------------------+

2 rows in set (0.00 sec)

 

mysql> show grants for [email protected]‘127.0.0.1‘;

+---------------------------------------------------------------------+

| Grants for [email protected]                                           |

+---------------------------------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘127.0.0.1‘ WITH GRANT OPTION |

+---------------------------------------------------------------------+

1 row in set (0.00 sec)

 

mysql> show grants for [email protected]‘%‘;

+-------------------------------------------+

| Grants for [email protected]%                         |

+-------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ |

+-------------------------------------------+

1 row in set (0.00 sec)

如上所示,[email protected]账号没有WITH GRANT OPTION选项,关于WITH GRANT OPTION选项,如果想让授权的用户,也可以将这些权限授予给其他用户,需要选项 “WITH GRANT OPTION“ 。说就是将权限传递给第三方。这也是上面[email protected]用户给其它用后授权报错的原因,如果以 [email protected]登录(此账号拥有WITHGRANT OPTION选项),创建用户并授权就不会有这个错误:

# mysql -host 127.0.0.1 -u root -p
Enter password: 

 

 

 

 

mysql>  grant all on eqmobilewarehouse.* to [email protected]‘192.168.%‘ identified by ‘test1249‘;

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

 

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

当然还有其它方面的原因也会引起这个错误,不过在这个案例当中,确实仅仅是因为上面原因引起。特此记录一下这个案例@!

原文地址:https://www.cnblogs.com/kerrycode/p/9198566.html

时间: 2024-10-27 11:58:45

ERROR 1044 (42000): Access denied for user ‘root‘@‘localhost‘的相关文章

ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'information_schema'

在我想把备份的数据库导入到本地数据的时候,发生这个错误,我使用的工具是dbForge Studio for MySQL ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'information_schema' 最终发现 通过下拉找到我想导入的数据库,OK了 ERROR 1044 (42000): Access denied for user 'root'@'localhost' to databa

ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'

mysql> use mysqlERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'mysql> exitBye[[email protected] ~]# service mysqld stop Stopping mysqld:                                           [  OK  ][[email protected] ~]# mysql

ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'(转)

解决ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' 原创 2014年05月11日 11:42:25 # /etc/init.d/mysql stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking & # mysql -u root mysql mysql> UPDATE user SET Passwor

mysql忘记root密码或报错:ERROR 1044 (42000): Access denied for user ”@’localhost’ to database ‘xx‘

有的时候忘记了root密码或其他用户的密码,登录的时候报错:ERROR 1044 (42000): Access denied for user ”@’localhost’ to database 'xx'.下面是具体的解决方法: 1.关闭mysql #service mysqld stop 2.屏蔽权限 # mysqld_safe --skip-grant-table 3.新开起一个终端输入 # mysql -u root mysql # mysql> UPDATE user SET Pass

ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

在centos下安装好的mysql,用root帐号连上mysql,查看数据库结果只有information_schema库,我原来的库和mysql库都不见了,然后执行use mysql提示错误,如下: mysql> use mysql; ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' 提示:ERROR 1044 (42000): Access denied for user ''@'loc

Mysql,ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' 刚在服务器上装上mysql,发现以root加密码的方式总是登录不了,而直接输入mysql则直接就可以登录了.或者以mysql –u root方式可以登录,但是实习上登录上去也是一个空用户(''@'localhost'),不是root用户,看不了其他数据库. 干货,删除空用户方法 1.关闭mysql service mysqld stop 或者

ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'db'

1.问题 在刚刚安装MySQL之后,进入到mysql环境下,创建数据库,出现下面的提示信息: ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'db' 2.原因 未用账号登录,而是直接用mysql进入,只拥有查看的权限: 3.解决方案 3.1 使用exit;退出mysql环境: mysql> exit; 3.2 重新使用账号登录 mysql -u root -p ERROR 1044 (42000): A

遇到错误ERROR 1044 (42000): Access denied for user ''@'localhost'to database 'mysql',的解决办法

新装的mysql,访问mysql数据库是遇到问题:ERROR 1044 (42000): Access denied for user ''@'localhost'to database 'mysql', [[email protected] mysql-5.1.61]# mysql -u root -p Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection

ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'ambari'

配置Ambari远程maridb 报错: ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'ambari' 在环境搭建的过程中,在 #用Ambari用户(上面设置的用户)登录mysql ,(没有密码) mysql -u ambari -p use ambari: source /var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql 遇到了: