从供应商那边接手一个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 xxx@'192.168.%' identified by 'xxx';
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'xxxx'
mysql> 

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

mysql> select current_user() from dual;
+----------------+
| current_user() |
+----------------+
| root@localhost |
+----------------+
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 root@'localhost';
+--------------------------------------------------------------+
| Grants for root@localhost                                    |
+--------------------------------------------------------------+
| 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 root@'127.0.0.1';
+---------------------------------------------------------------------+
| Grants for root@127.0.0.1                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)
 
mysql> show grants for root@'%';
+-------------------------------------------+
| Grants for root@%                         |
+-------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' |
+-------------------------------------------+
1 row in set (0.00 sec)

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

# mysql -host 127.0.0.1 -u root -p
Enter password: 
 
 
 
 
mysql>  grant all on xxx.* to xxx@'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)

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

mysql 创建帐号出现 Access denied for user 'root'@'localhost'错误(转载)的更多相关文章

  1. mysql Access denied for user root@localhost错误解决方法总结(转)

    mysql Access denied for user root@localhost错误解决方法总结(转) mysql Access denied for user \'root\'@\'local ...

  2. (转载)解决MySql 数据库 提示:1045 access denied for user 'root'@'localhost' using password yes

    今天想用用MySQL 数据库  谁知道老提示 1045 access denied for user 'root'@'localhost' using password yes 最后在csdn 上找到 ...

  3. 转: windows系统下mysql出现Error 1045(28000) Access Denied for user 'root'@'localhost'

    windows系统下mysql出现Error 1045(28000) Access Denied for user 'root'@'localhost' 转自 http://zxy5241.space ...

  4. Mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    Mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) Linux: MyS ...

  5. yum 安装 Mysql error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 开启远程连接 修改登入密码 忘记root密码 配置防火墙规则 随手mark

    yum 安装 MYsql:        yum install mysql mysql-server mysql-devel -y 1.1 登入报错: ERROR 1045 (28000): Acc ...

  6. 解决MySql 数据库 提示:1045 access denied for user 'root'@'localhost' using password yes

    今天想用用MySQL 数据库  谁知道老提示 1045 access denied for user 'root'@'localhost' using password yes 最后在csdn 上找到 ...

  7. mysql Access denied for user root@localhost错误解决方法总结

    原文:http://www.111cn.net/database/mysql/44142.htm Access denied for user 'root'@'localhost' (using pa ...

  8. Ubuntu下 MySQL的“ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)”

    今天闲来无事,在Ubuntu上掏鼓一下mysql.但尴尬的是,当我输入mysql -u root -p的时候,抛出了一个错误:ERROR 1045 (28000): Access denied for ...

  9. 登录mysql 报 Access denied for user 'root'@'localhost' 错误

    安装mysql后登录提示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:yes) 解决如下 ...

随机推荐

  1. 055-for循环中break的使用

    <?php ;;$x++){ //省略表达式2的for循环将是无限循环 echo "$x<br />"; ){ break; //使用if语句控制退出无限循环 } ...

  2. Oracle SQL语句记录

    1.oracel 查看表空间使用情况. ) AS free_space, tablespace_name FROM dba_free_space GROUP BY tablespace_name; ) ...

  3. 三、ReactJS、jsx、 Component 特性

    reactjs特性: 基于组件(Component)化思考 用 JSX 进行声明式(Declarative)UI 设计 使用 Virtual DOM Component PropType 错误校对机制 ...

  4. 二、【重点】环境安装:通过淘宝 cnpm 快速安装使用 React,生成项目,运行项目、安装项目

    1.cnpm代替npm 如果你的系统还不支持 Node.js 及 NPM 可以参考我们的 Node.js 教程. 我们建议在 React 中使用 CommonJS 模块系统,比如 browserify ...

  5. hdu 1160 上升序列 dp

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. opencv 读写XML YML

    //序列没有标签 CvMemStorage *mem = cvCreateMemStorage(0); CvFileStorage *file = cvOpenFileStorage("e: ...

  7. POJ-3629 模拟

    A - Card Stacking Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  8. 翻翻棋(找规律问题)(FZU Problem 2230)

    题目是这样的: FZU Problem 2230 象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将.根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃 ...

  9. 201803-2 碰撞的小球 Java

    思路: 直接按照题意模拟,感觉没什么太好的办法.另外注意:int这种基础数据类型不能用equals这个方法 ,必须是Integer类型 import java.util.Scanner; public ...

  10. java基础——深拷贝和浅拷贝的区别

    浅拷贝:对基本数据类型进行值传递,对引用数据类型进行引用传递般的拷贝,此为浅拷贝. 深拷贝:对基本数据类型进行值传递,对引用数据类型船舰一个新的对象,并复制内容,这是深拷贝.