下面是从官档中摘抄的关于MySQL在登陆认证时,从user表选择用户验证的先后顺序。

mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';

mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'

-> WITH GRANT OPTION;

mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';

mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'

-> WITH GRANT OPTION;

Two accounts have a user name of monty and a password of some_pass. Both are superuser accounts with full privileges to do anything. The 'monty'@'localhost' account can be used only when connecting from the local host. The 'monty'@'%' account uses the '%' wildcard for the host part, so it can be used to connect from any host.

上面创建的两个monty用户都是具有所有权限的超级用户。其中monty@localhost用户只能从本地主机连接数据库,monty@%用户可以从任意主机连接数据库。

The 'monty'@'localhost' account is necessary if there is an anonymous-user account for localhost. Without the 'monty'@'localhost' account, that anonymous-user account takes precedence when monty connects from the local host and monty is treated as an anonymous user. The reason for this is that the anonymous-user account has a more specific Host column value than the 'monty'@'%' account and thus comes earlier in the user table sort order. (user table sorting is discussed in Section 6.2.4, “Access Control, Stage 1: Connection Verification”.)

如果数据库存在只供本地主机访问的匿名用户(''@'localhost'),那么monty@localhost账户就是必须的。如果没有monty@localhost账户,当monty用户在本地主机建立数据库连接时,匿名账户的优先级更高,这时monty用户会被作为匿名用户处理。原因为:本地匿名账户(''@'localhost')比'monty'@'%'账户具有更具体的主机列值,从而在用户表排序中位置出现靠前。

Your identity is based on two pieces of information:

The client host from which      you connect

Your MySQL user name

It is possible for the client host name and user name of an incoming connection to match more than one row in the user table. The preceding set of examples demonstrates this: Several of the entries shown match a connection from thomas.loc.gov by fred.

When multiple matches are possible, the server must determine which of them to use. It resolves this issue as follows:

Whenever the server reads the user table into memory, it sorts the rows.

When a client attempts to connect, the server looks through the rows      in sorted order.

The server uses the first row that matches the client host name and      user name.

MySQL数据库是通过下面两条信息来验证登陆标识的:

连接过来的主机信息

连接过来的MySQL用户名

当连接MySQL时,有多个登陆标识被匹配上,MySQL服务按照下面的方法来决定哪条匹配信息被使用:

无论何时MySQL服务都读取user表到内存中,并对其排序

当一个客户端尝试连接MySQL数据库,MySQL服务浏览排序后的user表数据

MySQL服务使用匹配上host和user的第一行数据

The server uses sorting rules that order rows with the most-specific Host values first. Literal host names and IP addresses are the most specific. (The specificity of a literal IP address is not affected by whether it has a netmask, so 192.168.1.13 and 192.168.1.0/255.255.255.0 are considered equally specific.) The pattern '%' means “any host” and is least specific. The empty string '' also means “any host” but sorts after '%'. Rows with the same Host value are ordered with the most-specific User values first (a blank User value means “any user” and is least specific). For rows with equally-specific Host and User values, the order is indeterminate.

MySQL服务对user表的排序规则为有最具体的host值排到首位。文本形式的主机名和ip地址是最具体的。(文本形式的IP地址不受netmask的影响,因此192.168.1.13和192.168.1.0/255.255.255.0被认为同样具体的。)'%'形式表示“any host”,是最少具体的,因此排序位置靠后。而空字符串('')也表示“any host”,但是排序在'%'之后。如果user表排序后host值一样,那么有最具体的user值的行排到首位(user值为空时表示“any user”并且是最少具体的)。对于同样具体的host和user值,在user表中的排序是不确定的。

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     | ...

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

When a client attempts to connect, the server looks through the sorted rows and uses the first match found. For a connection from localhost by jeffrey, two of the rows from the table match: the one with Host and User values of 'localhost' and '', and the one with values of '%' and 'jeffrey'. The 'localhost' row appears first in sorted order, so that is the one the server uses.

当一个客户端尝试连接MySQL,MySQL服务去过滤排序后的user表,并使用第一个被匹配到的行(通过host和user去匹配)。对于一个来自localhost用户名为jeffrey的连接,user表中两行被匹配到:一行是host和user值分别为'localhost'和'',一行是host和user值分别为'%'和'jeffrey'。'localhost'行出现在排序后的user表的前面位置,因此host和user值为'localhost'和''的用户标识被MySQL服务使用。

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.

来自thomas.loc.gov主机用户名为jeffrey的连接匹配到上表的第一行数据,反之来自其他主机用户名为jeffrey的连接匹配到第二行数据。

Note

It is a common misconception to think that, for a given user name, all rows that explicitly name that user are used first when the server attempts to find a match for the connection. This is not true. The preceding example illustrates this, where a connection from thomas.loc.gov by jeffrey is first matched not by the row containing 'jeffrey' as the User column value, but by the row with no user name. As a result, jeffrey is authenticated as an anonymous user, even though he specified a user name when connecting.

一个常见的误解是,对于一个给定的用户名,当MySQL服务尝试去匹配连接所用的用户标识时,应该优先使用包含明确名称的行。事实并非如此。前面的例子说明了这一点,来自thomas.loc.gov主机用户名为jeffrey的连接第一个匹配的不是user列值包含'jeffrey'的行,而是user列值为空的行。结果,jeffrey被作为匿名用户去认证,即使在连接时指定了明确的user值。

If 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 matching user 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 treating jeffrey 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.

mysql的连接名和用户名_MySQL登陆认证用户名先后顺序相关推荐

  1. mysql远程连接打不开_MySql远程连接无法打开解决办法

    MySql远程连接无法打开解决办法 1.改表法. 请使用mysql管理工具,如:SQLyog Enterprise.navicate mysql 可能是你的帐号不允许从远程登陆,只能在localhos ...

  2. mysql的连接名是哪个文件_mysql连接名是什么

    {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],&q ...

  3. 连接数mysql证登录名和密码_mysql连接数

    mysql 最大连接数 show variables like '%max_connections%'; 当前连接数 show full processlist; MySQL查看最大连接数和修改最大连 ...

  4. mysql 改表名锁表_mysql修改字段防止锁表

    步骤1: 修改一个大表的字段,add column或者drop column,操作后表会锁住,此时查询ok,insert和update会一直等待锁.如图. 解决方案: 1.基于要操作的表创建一个临时表 ...

  5. MySQL左连接还有过滤条件_MySQL左连接问题,右表做筛选,左表列依然在?

    问 题 原料 两张表,一张user表,一张user_log表(这个例子举的不好) CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, ...

  6. mysql登录如何重置密码忘记_MySql登陆密码忘记了怎么办?MySQL重置root密码方法...

    MySQL有时候忘记了root密码是一件伤感的事.这里提供Windows 和 Linux 下的密码重置方法. Windows: 1.以系统管理员身份登陆系统. 2.打开cmd-----net star ...

  7. mysql用户连接次数失败限制_mysql数据库限制多次登录失败,限定用户重试时间...

    前言 最近的项目开始进行安全测试,其中有一个安全问题是这样的. 应该增加用户登录失败处理功能,限制非法登录次数. 建议是增加mysql数据库的登陆失败的锁定功能. 相信大家也都会遇到这样的问题,在这里 ...

  8. mysql查询重复用户名_mysql取出以上用户名(去除重复),score值最高的所有记录,查出重复记录...

    tt 表: 有如下数据: insert into tt values('yy1',35) ; insert into tt values('yy1',36) ; insert into tt valu ...

  9. mysql数据库主机名是什么_mysql数据库主机名是什么

    {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],&q ...

最新文章

  1. 7 Papers Radios | GCN大佬公开博士论文;谷歌提出扩展型BERT架构
  2. mysql单列索引和多列索引_mysql 单列索引与多列索引
  3. win10网络不出现计算机列表,win10网络发现已关闭网络计算机和设备不可见怎么办?...
  4. 20159206《网络攻防实践》第四周学习总结
  5. 3.1_ _2_ 内存管理的概念
  6. 5G精华问答:5G的速度到底有多快?| 技术头条
  7. linux输入ls后不显示_零基础学习之Linux基础命令小结
  8. zabbix items复制
  9. 做一个计算器_如何设计一个JavaScript插件系统,编程思维比死磕API更重要
  10. 后缀转中缀表达式_中缀转后缀表达式代码实现(下)及计算器完整版
  11. Audio播放流程(二)---NuPlayer流程之setDataSource
  12. Windows server 2008计划任务(批处理命令)不执行
  13. java连接点菜基站_基于JAVA的电信基站接口调用代码实例
  14. 小红书 标签 HTML5,牛宝-手机客户端
  15. 显卡参数详解[原创]
  16. 5GgNB和ng-eNB的主要功能
  17. 零基础Bootstrap入门教程(16)--模态框
  18. spring boot oauth2 facebook
  19. Spark安装-环境搭建
  20. 【问题】【实用】java服务假死【CLOSE_WAIT】【线程WAITING】

热门文章

  1. Ant Design Icon图标使用
  2. 通过TextSwitcher实现广告栏内容动画切换
  3. 苹果新推出的IPod播放器为三星奏出美妙乐符
  4. 这台笔记本最适合程序员编程!!
  5. 领域驱动设计——项目分层与项目落地
  6. 【调剂】河北农业大学2020年硕士研究生招生调剂工作办法
  7. ros源码下载及编译
  8. Nginx 安装、解决办法
  9. 热成像进入AI人工智能时代!精准人脸识别体温计,实名制测量体温
  10. 大学计算机英语要求,2015级本科生大学英语、计算机分级考试要求.doc