• 【转载整理】 mysql 验证顺序


    To see how this works, suppose that the user table looks like this:

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

    | Host      | User     | ...

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

    | %         | root     | ...

    | %         | jeffrey  | ...

    | localhost | root     | ...

    | localhost |          | ...

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

    When the server reads the table into memory, it sorts the rows using the rules just described. The result after sorting looks like this:

    MySQL服务读取上面的user表到内存中,使用上面描述的排序规则对行进行排序。排序后的结果如下:

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

    | Host      | User     | ...

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

    | localhost | root     | ...

    | localhost |          | ...

    | %         | jeffrey  | ...

    | %         | root     | ...

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

     

     

     

     

     

     

    Here is another example. Suppose that the user table looks like this:

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

    | Host           | User     | ...

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

    | %              | jeffrey  | ...

    | thomas.loc.gov |          | ...

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

    The sorted table looks like this:

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

    | Host           | User     | ...

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

    | thomas.loc.gov |          | ...

    | %              | jeffrey  | ...

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

    A connection by jeffrey from thomas.loc.gov is matched by the first row, whereas a connection by jeffrey from any host is matched by the second.

     

     

     

     

     

    f you are able to connect to the server, but your privileges are not what you expect, you probably are being authenticated as some other account. To find out what account the server used to authenticate you, use the CURRENT_USER() function. (See Section 12.14, “Information Functions”.) It returns a value in user_name@host_name format that indicates the User and Host values from the matchinguser table row. Suppose that jeffrey connects and issues the following query:

    mysql> SELECT CURRENT_USER();

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

    | CURRENT_USER() |

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

    | @localhost     |

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

    The result shown here indicates that the matching user table row had a blank User column value. In other words, the server is treatingjeffrey as an anonymous user.

    Another way to diagnose authentication problems is to print out the user table and sort it by hand to see where the first match is being made.

     

     

     

    总结

    HOST优先级高于用户名      ------》     ‘’@ip/host    优先级高于     用户名@‘%’       (1.1.1.%视同%)

    select current_user()    显示库中匹配上的用户名主机权限。

     

     

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

    另转载: localhost 与127.0.0.1

    如果仔细查看MYSQL的权限表,会发现存在主机名为 localhost 的记录,也存在主机名为 127.0.0.1 的记录,那这两着分别在什么时候会用到呢?

    使用 /usr/local/mysql/bin/mysql -u root -p访问MYSQL服务器的时候,如果使用了 -h 参数,mysql 就会通过 TCP/IP 的方式去连接服务器;如果没有 -h 参数,默认会使用 UNIX socket 方式。

    如果通过 TCP/IP 方式进来的连接,MYSQL服务器接收到的来源主机是 127.0.0.1;如果是 UNIX socket 方式,MYSQL服务器接收到的来源主机是 localhost。

    如果MYSQL服务器开启了 skip_name_resolve,MYSQL服务器就不会把接收到的 IP 地址转化为域名,所以前者的current_user就是 root@'127.0.0.1',后者的current_user就是 root@'localhost'。

    如果按照MYSQL的默认配置,skip_name_resovle 是OFF,MYSQL服务器就会将 127.0.0.1 转换为 localhost,那么前者和后者两种连接的 current_user 都是 root@'localhost'
    ---------------------
    作者:RichardXu
    来源:CSDN
    原文:https://blog.csdn.net/topasstem8/article/details/18357789
    版权声明:本文为博主原创文章,转载请附上博文链接!

     

  • 相关阅读:
    从零开始写自己的PHP框架系列教程[前言]
    从零开始写自己的PHP框架系列教程(二)[App.php]
    Nginx
    常见的CSS
    常用JS代码
    jq常用
    EMMET 的HTM自动生成
    JS的小判断
    ARM寄存器与ATPCS/AAPCS
    关于笔记本电脑随想
  • 原文地址:https://www.cnblogs.com/infaaf/p/10531650.html
Copyright © 2020-2023  润新知