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

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

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

  1. mysql> select current_user() from dual;
  1. +----------------+
  1. | current_user() |
  1. +----------------+
  1. | root@localhost |
  1. +----------------+
  1. 1 row in set (0.00 sec
  1.  
  1. mysql> select host,user from user where user='root';
  1. +-----------+----------+
  1. | host      | user     |
  1. +-----------+----------+
  1. | %         | root     |
  1. | 127.0.0.1 | root     |
  1. | ::1       | root     |
  1. | localhost | root     |
  1. +-----------+----------+
  1. 7 rows in set (0.00 sec)
  1.  
  1. mysql>  show grants for root@'localhost';
  1. +--------------------------------------------------------------+
  1. | Grants for root@localhost                                    |
  1. +--------------------------------------------------------------+
  1. | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'            |
  1. | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
  1. +--------------------------------------------------------------+
  1. 2 rows in set (0.00 sec)
  1.  
  1. mysql> show grants for root@'127.0.0.1';
  1. +---------------------------------------------------------------------+
  1. | Grants for root@127.0.0.1                                           |
  1. +---------------------------------------------------------------------+
  1. | GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION |
  1. +---------------------------------------------------------------------+
  1. 1 row in set (0.00 sec)
  1.  
  1. mysql> show grants for root@'%';
  1. +-------------------------------------------+
  1. | Grants for root@%                         |
  1. +-------------------------------------------+
  1. | GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' |
  1. +-------------------------------------------+
  1. 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选项),创建用户并授权就不会有这个错误,如下所示:

  1. # mysql -host 127.0.0.1 -u root -p
  1. Enter password:
  1.  
  1.  
  1.  
  1.  
  1. mysql>  grant all on xxx.* to xxx@'192.168.%' identified by 'test1249';
  1. Query OK, 0 rows affected, 1 warning (0.00 sec)
  1.  
  1.  
  1. mysql> flush privileges;
  1. 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. Spring-ResolvableType可解决的数据类型

    ResolvableType,可解决的数据类型.它为java语言中的所有类型提供了相同的数据结构,其内部封装了一个java.lang.reflect.Type类型的对象. 在讲解这个数据结构之前,首先 ...

  2. Spring Tools 4 STS没有创建Dynamic Web Project的选项 以及 Spring Tools 4 STS New 菜单没有Spring Bean Configuration File选项

    Spring Tools 4 STS没有创建Dynamic Web Project的选项 STS4默认不带Dynamic Web Project插件. 解决方法:1.打开:Help 选择 Instal ...

  3. html使用aes进行加密

    1.导入 aes.js 文件 !function(t,n){*t.length},toString:function(t){);o<r;o++){]>>>-o%*&;n ...

  4. 为什么 execute(`echo 中文`) 输出中文源码?

    为什么 execute(echo 中文) 输出中文源码? import win.ui; /*DSG{{*/ var winform = win.form(text="管道演示";r ...

  5. DispatcherServlet继承体系

    GenericServlet                 implements Servlet, ServletConfig, java.io.Serializable | HttpServlet ...

  6. C++ DirectShow读取摄像头后然后保存图像数据

    #include <stdio.h> #include "camerads.h" #include <highgui.h> const char *g_sz ...

  7. jQuery实现轮播图--入门

    jQuery是一个前台的框架. 主要函数: setInterval 语法:setInterval(code,millisec[,"lang"]) cdoe:需要执行的代码或者要调用 ...

  8. ADC分辨率

    转载:http://www.rationmcu.com/elecjc/1874.html 今天给大家简单介绍一下ADC器件的常识. ADC,模数转换器,功能是把模拟电压转换成数字量. 概念听的模糊,说 ...

  9. Python笔记_第五篇_Python数据分析基础教程_NumPy基础

    1. NumPy的基础使用涵盖如下内容: 数据类型 数组类型 类型转换 创建数组 数组索引 数组切片 改变维度 2. NumPy数组对象: NumPy中的ndarray是一个多维数组对象,该兑现共有两 ...

  10. 2.3 使用Android Studio 简单设计UI界面

    首先 创建一个新的项目找到app 文件目录下的layout的 activity_main.xml 因为Android Studio 是可视化的,所有操作都可以在图形界面进行. 该res 界面当中  d ...