zoukankan      html  css  js  c++  java
  • X mysql 数据库增加用户与为用户授权。 ERROR 1133 (42000): Can't find any matching row in the user table。

    ERROR 1133 (42000): Can't find any matching row in the user table

    1、问题描述

    使用set password for 'root'@'localhost'=password('MyNewPass4!'); 命令修改mysql数据库root用户密码提示**ERROR 1133 (42000): Can't find any matching row in the user table**错误

    2、主要原因

    • 错误提示的字面意思:在用户表中找不到任何匹配的行

    • 登录mysql执行以下命令

    use mysql;
    select Host,User from user;
    • 1

    这里写图片描述

    主要原因是修改密码的条件不否

    3、解决办法

    • set password for 'root'@'localhost'=password('MyNewPass4!'); 代码中的localhost修改%,与数据库Host字段值一致
    set password for 'root'@'%'=password('MyNewPass4!');
    • 刷新
    flush privileges;

    这里写图片描述

    ===================================================================================================================

         

    自我测试案例如下  :

    因为在客户端进行连接的时候没有权限,报错如下:

    在进行授权的时候发现 报错 1133,如下所示。

    [root@localhost][mysql]> grant all privileges on *.* to 'root'@'%' with grant option;
    ERROR 1133 (42000): Can't find any matching row in the user table

    这是因为,在授权进行授权的时候 ,需要读取 mysql.user 表中的记录。如果没有   ‘root’@'%'  这条记录,那么就不能授权,如下所示

    [root@localhost][mysql]> select Host,User from user;
    +----------------+---------------+
    | Host           | User          |
    +----------------+---------------+
    | 192.168.17.182 | repl          |
    | localhost      | mysql.session |
    | localhost      | mysql.sys     |
    | localhost      | root          |
    +----------------+---------------+
    4 rows in set (0.00 sec)

    那么需要进行 增加用户的操作:

    [root@localhost][mysql]> create user 'root'@'%' identified by '123456';
    Query OK, 0 rows affected (0.00 sec)

    然后我们再来查询 mysql.user 的记录,可以发现有了  ‘root’@'%'  这条记录  :

    [root@localhost][mysql]> select host,user from user;
    +----------------+---------------+
    | host           | user          |
    +----------------+---------------+
    | %              | root          |
    | 192.168.17.182 | repl          |
    | localhost      | mysql.session |
    | localhost      | mysql.sys     |
    | localhost      | root          |
    +----------------+---------------+
    5 rows in set (0.00 sec)

    下面再进行授权就没有问题了:

    [root@localhost][mysql]> flush privileges;
    Query OK, 0 rows affected (0.01 sec)
    
    [root@localhost][mysql]> grant all privileges on *.* to 'root'@'%';
    Query OK, 0 rows affected (0.01 sec)

    也可以如下进行授权:

    [root@localhost][mysql]> grant all privileges on *.* to 'root'@'%' with grant option;
    Query OK, 0 rows affected (0.00 sec)
    
    [root@localhost][mysql]> 
    [root@localhost][mysql]> flush privileges;
    Query OK, 0 rows affected (0.01 sec)

    然后在客户端可以访问了。

  • 相关阅读:
    5555
    3333
    4444
    试验2
    Android之TextView灵活使用(转载)
    Android之使用Android-query框架进行开发(一)(转载)
    Android 之Html的解析(使用jsoup)
    Android之动画的学习(转载)
    Android之官方下拉刷新控件SwipeRefreshLayout
    Android之sqlite的使用 (转载)
  • 原文地址:https://www.cnblogs.com/chendian0/p/13903000.html
Copyright © 2011-2022 走看看