用户管理模块之mysql.user
不使用-h参数来指定登录host,默认会连接localhost,仅当mysql.user表中有一条对应的localhost访问授权(username@%不对任何主机做限制也不行)时登录才成功,否则登录会被拒绝。
虚拟机VMUest上安装两个MySQL实例,两个实例搭建了Master(端口3306)-Slave(端口3307),主从数据完全一致。
mysql> select Host,User,Password from mysql.user;
+-----------------------+--------+-------------------------------------------+
| Host | User | Password |
+-----------------------+--------+-------------------------------------------+
| localhost | root | *6B4F89A54E2D27ECD7E8DA05B4AB8FD9D1D8B119 |
| localhost.localdomain | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| localhost.localdomain | | |
| % | mydba | *80BF8C1F4008F25267DB194E29D2E8BC20C836ED |
| % | backup | *975B2CD4FF9AE554FE8AD33168FBFC326D2021DD |
| 192.168.85.% | repl | *A424E797037BF97C19A2E88CF7891C5C2038C039 |
+-----------------------+--------+-------------------------------------------+
9 rows in set
使用root用户登录
#不指定-h参数,默认就会走localhost
[uest@VMUest ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select @@port;
+--------+
| @@port |
+--------+
| |
+--------+
row in set (0.00 sec) mysql> exit
Bye
[uest@VMUest ~]$ mysql -uroot -p -P3307
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select @@port;
+--------+
| @@port |
+--------+
| |
+--------+
row in set (0.00 sec) mysql> exit
Bye
#指定-h+ip参考,同时指定-P端口
[uest@VMUest ~]$ mysql -uroot -p -h127.0.0. -P3306
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select @@port;
+--------+
| @@port |
+--------+
| |
+--------+
row in set (0.00 sec) mysql> exit
Bye
[uest@VMUest ~]$ mysql -uroot -p -h127.0.0. -P3307
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select @@port;
+--------+
| @@port |
+--------+
| |
+--------+
row in set (0.00 sec) mysql> exit
Bye
#指定-h+localhost参考,同时指定-P端口
[uest@VMUest ~]$ mysql -uroot -p -hlocalhost -P3307
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select @@port;
+--------+
| @@port |
+--------+
| |
+--------+
row in set (0.00 sec) mysql> exit
Bye
[uest@VMUest ~]$
从上面的结果可以看出只有在指定-h+ip,同时指定-P端口的情况下,才能连接到指定的端口中。localhost实际就是指定通过socket连接!!!
注意:我们的mysql.user表中root@'127.0.0.1'对应的Password为空(即不需要输入密码),但实际登录过程需要输入密码。这是受skip_name_resolve参数影响
mysql> show variables like '%skip_name_resolve%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| skip_name_resolve | OFF |
+-------------------+-------+
1 row in set
该参数的值为OFF,root@'127.0.0.1'会转化为root@'localhost'登录,它使用的是root@'localhost'定义的密码。可尝试开启skip_name_resolve参数(配置文件my.cnf中添加skip_name_resolve=1),然后使用空密码登录。
mysql.user表中第5条记录Host='localhost',User和Password字段为空,也就是localhost可以不指定用户、密码直接登录
[uest@VMUest ~]$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select @@port;
+--------+
| @@port |
+--------+
| |
+--------+
row in set (0.00 sec) mysql>
还是有一些小细节需要注意。引用iVictor一段话:'t1'@'%'中包含't1'@'127.0.0.1',如果开启skip_name_resolve参数,则't1'@'%'中定义的密码可用于't1'@'127.0.0.1'的登录;如果没有开启该参数,则't1'@'127.0.0.1'会转化为't1'@'localhost'登录,如果用户表存在't1'@'localhost'条目,根据最精确匹配原则(Host->User),需要使用't1'@'localhost'对应的密码登录;如果用户表不存在't1'@'localhost'条目,'t1'@'%'定义的密码依旧适用。
从库开启skip_name_resolve参数,从库可以使用 mysql -h127.0.0.1 -P3307 -umydba -p 登录,对应user表中条目mydba@'%';主库没有开启skip_name_resolve参数,它如果尝试使用 mysql -h127.0.0.1 -P3306 -umydba -p 登录,会转化为mydba@'localhost',user表中没有此条目,登录拒绝!
MySQL存放于内存结构中的权限信息何时被更新:
FLUSH PRIVILEGES会强行让MySQL更新Load到内存中的权限信息;GRANT、REVOKE或者CREATE USER和DROP USER操作会直接更新内存中的权限信息;重启MySQL会让MySQL完全从grant tables中读取权限信息。
内存结构中的权限信息更新之后对已经连接上的用户何时生效:
对于Global Level的权限信息的修改,仅仅只有更改之后新建连接才会用到,对于已经连接上的session并不会受到影响。
对于Database Level的权限信息的修改,只有当客户端请求执行了“use database_name”命令之后,才会在重新校验中使用到新的权限信息。
对于Table Level和Column Level的权限,在下一次需要使用到该权限的Query被请求的时候生效。
用户管理模块之mysql.user的更多相关文章
- Vue + Element UI 实现权限管理系统 前端篇(十二):用户管理模块
用户管理模块 添加接口 在 http/moduls/user.js 中添加用户管理相关接口. import axios from '../axios' /* * 用户管理模块 */ // 保存 exp ...
- TestCase--网站创建新用户管理模块
对于web测试,用户权限管理模块是必测的一个点,所以今天就来总结一下创建新用户管理模块的测试用例 参考图如下: 测试用例设计如下: 一.功能测试 1. 什么都不输入,单击“立即提交”,页面是否有提示 ...
- 循序渐进VUE+Element 前端应用开发(15)--- 用户管理模块的处理
在前面随笔介绍了ABP+Vue前后端的整合处理,包括介绍了ABP的后端设计,以及前端对ABP接口API的ES6的封装,通过JS的继承类处理,极大减少了重复臃肿的代码,可以简化对后端API接口的封装,而 ...
- 【php增删改查实例】第十四节 - 用户管理模块(起步)
从这一节开始,开始着手开发部门管理模块. 之后的内容就在此基础上进行增加. 1.用户查询 在目录中建立一个user文件夹,作为我们用户管理的模块. 打开这个文件,新建一个userManage.html ...
- .NET快速信息化系统开发框架 V3.2 -> Web 用户管理模块编辑界面-组织机构选择支持级联选择
下拉框级联选择功能非常的实用,框架用户管理编辑界面对组织机构的选择在3.2版本中新增了级联选择的支持,让组织机构的选择更加的方便与高效,也不容易出错. 我们框架的组织机构结合实际分成了5种类型,分别为 ...
- 【php增删改查实例】第十五节 - 用户管理模块(删除确认)
假如有一天,用户找到你,说万一不小心手一抖,就点击了删除用户,不太好.能不能再误点的时候,再给个确认框,让用户进行二次确认. OK,用户是上帝.这边我们可以考虑用confirm方法进行开发. 参考代码 ...
- Python 42 mysql用户管理 、pymysql模块
一:mysql用户管理 什么是mysql用户管理 mysql是一个tcp服务器,应用于操作服务器上的文件数据,接收用户端发送的指令,接收指令时需要考虑到安全问题, ATM购物车中的用户认证和mysql ...
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->用户管理模块新增“重置用户密码”功能
不管是什么系统登录用户都有忘记密码的时候,忘记密码就进入不了系统.系统应该可以提供重置用户密码的功能.在我们框架中重置用户密码功能一般用用户管理员来完成.当然如果做得复杂点还可以由用户自己来重置(如: ...
- MySQL 安装 用户管理 常用命令
MySQL目录 数据库概览 数据库介绍 Why Choose MySQL MySQL的前世今生 MySQL的安装 Windows安装MySQL5.721 installer版 Windows安 ...
随机推荐
- Python with语句的概率,不多说了直接上代码!
python中的with语句用于访问资源.它确保执行指定的__exit__(“清理”)操作,而不管释放被访问资源的处理过程中的错误或异常,例如读取和写入文件后自动关闭.线程中锁的自动获取和释放等. p ...
- bzoj1026题解
[解题思路] 数位DP.f[i][j]表示以j结尾的i位数中windy数的个数,转移方程f[i][j]=Σf[i-1][k](|j-k|>1). 基于f数组,我们可以统计出1~n内的windy数 ...
- NX二次开发-UDO用户自定义对象(UFUN)【持续完善】
每当提起UDO总是会让我想起大专毕业那会失业找工作,后来有个宝贵机会去了软件公司上班,拿到了我人生中的第一个NX二次开发项目,一个关于测量汽车前后左右摄像头的项目.当时那个项目就用到了UDO,对于只看 ...
- Python 数据结构_堆栈
目录 目录 堆栈 堆栈 堆栈是一个后进先出(LIFO)的数据结构. 堆栈这个数据结构可以用于处理大部分具有后进先出的特性的程序流 . 在堆栈中, push 和 pop 是常用术语: push: 意思是 ...
- 剑指offer——09青蛙跳台阶
题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果). 题解: 说俗一点,就是找规律: 不不,首先,我们分析一下,青蛙第一 ...
- codeforces round#524 C. Masha and two friends /// 矩形切割
题目大意: 给定n行m列的黑白棋盘如下 给定矩形的左下点x1 y1和右上点x2 y2将这个区域都涂成白色 再给定矩形的左下点x3 y3和右上点x4 y4将这个区域都涂成黑色 求最后棋盘内有分别多少个白 ...
- 错误Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInputStream排查思路
spark1(默认CDH自带版本)不存在这个问题,主要是升级了spark2(CDHparcel升级)版本安装后需要依赖到spark1的旧配置去读取hadoop集群的依赖包. 1./etc/spark2 ...
- C++ vector操作--往列表中添加或更新内容
有个列表,往里面添加内容,如果对象已存在,只更新其属性,否则添加新一项. #include <iostream> #include <string> #include < ...
- SpringCloud学习笔记《---05 Zuul---》基础篇
- wish - 简单的窗口式(windowing) shell
总览 wish [filename] [arg] [arg ...] 选项 -colormap new 指定窗口使用一个新的私有的调色板(colormap)而不使用给屏幕的缺省的调色板. -displ ...