xml地图|网站地图|网站标签 [设为首页] [加入收藏]

奥门金沙手机娱乐网址MySQL验证客商权限的诀窍,mysql验证顾客权限

时间:2019-12-08 18:57来源:计算机
MySQL验证顾客权限的法子,mysql验证客户权限 文化汇总 因为MySQL是应用User和Host八个字段来规定顾客地方的,那样就带给贰个难点,正是叁个客商端到底归属哪个host。 假如叁个客商端同

MySQL验证顾客权限的法子,mysql验证客户权限

文化汇总

因为MySQL是应用User和Host八个字段来规定顾客地方的,那样就带给贰个难点,正是叁个客商端到底归属哪个host。
假如叁个客商端同一时间合作几个Host,对客商的明确将如约上面包车型大巴优先级来排

  • 基本思想越标准的相称越优先
  • Host列上,越是明确的Host越优先,[localhost, 192.168.1.1, wiki.yfang.cn] 优先于[192.168.%, %.yfang.cn],优先于[192.%, %.cn],优先于[%]
  • User列上,显然的username优先于空username。(空username相称全部顾客名,即无名客户相配全体客商)
  • Host列优先于User列考虑

当你登陆mysql服务器之后,你可以选拔user(卡塔尔(قطر‎和current_user(卡塔尔国来检查你登入的客商。

  • user(卡塔尔(英语:State of Qatar) 重回您总是server时候钦命的客商和主机
  • current_user()重临在mysql.user表中格外到的客户和主机,那将规定你在数据库中的权限

当您登入服务器并奉行MySQL的通令时,系统将检查你眼下的客商(current_user卡塔尔是或不是有权力实行业下操作。

  • 率先检查user表中的全局权限,假若满足条件,则实施操作
  • 假若地方的曲折,则检查mysql.db表中是或不是有知足条件的权能,若是满意,则实行操作
  • 大器晚成旦地点的波折,则检查mysql.table_priv和mysql.columns_priv(借使是储存进度操作则检查mysql.procs_priv卡塔尔国,倘使满意,则实践操作
  • 要是以上检查均退步,则系统谢绝试行操作。

测试进度
创办3个客户名相像,HOST和权限都不可以偏概全包车型客车USELAND

mysql> grant select on *.* to ''@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)
mysql> grant select,createon *.* to 'bruce'@'10.20.0.232' identified by '123';
Query OK, 0 rows affected (0.01 sec)
mysql> grant select,create,deleteon *.* to 'bruce'@'%' identified by'123';
Query OK, 0rows affected (0.00 sec)

从别的三个机器登录过来

[[email protected] ~]# mysql -ubruce -p -h10.20.0.231
Enter password: 
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MySQL connection id is 5
Server version: 5.5.20-log MySQL Community Server (GPL)
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome tomodify and redistribute it under the GPL v2 license
Type 'help;' or 'h' for help. Type'c'to clear the current inputstatement.
MySQL [(none)]> show grants;
+-------------------------------------------------------------------------------------------------------------------------+
| Grants for [email protected]                       |
+-------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, CREATEON *.* TO 'bruce'@'10.20.0.232' IDENTIFIED BY PASSWORD'*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' |
+-------------------------------------------------------------------------------------------------------------------------+
1 row inset (0.00 sec)
MySQL [(none)]> select user(), current_user();
+-------------------+-------------------+
| user()   | current_user() |
+-------------------+-------------------+
| [email protected] | [email protected] |
+-------------------+-------------------+
1 row in set (0.03 sec)

刚毅的user,host,举办准确相称,找到客户为'bruce'@'10.20.0.232'
删除掉那些顾客再登入

mysql> delete from mysql.userwhereuser='bruce'andhost='10.20.0.232';
Query OK, 1row affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

[[email protected] ~]# mysql -ubruce -p -h10.20.0.231
Enter password: 
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MySQL connection id is 6
Server version: 5.5.20-log MySQL Community Server (GPL)
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome tomodify and redistribute it under the GPL v2 license
Type 'help;' or 'h' for help. Type'c'to clear the current inputstatement.

MySQL [(none)]>show grants;
+-----------------------------------------------------------------------------------------------------------------------+
| Grants for [email protected]%                         |
+-----------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, DELETE, CREATEON*.* TO 'bruce'@'%' IDENTIFIED BYPASSWORD'*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' |
+-----------------------------------------------------------------------------------------------------------------------+
1 row inset (0.00 sec)
MySQL [(none)]> select user(), current_user();
+-------------------+----------------+
| user()   | current_user() |
+-------------------+----------------+
| [email protected] | [email protected]%  |
+-------------------+----------------+
1 row in set (0.00 sec)

那时候卓殊的客户是[email protected]%
下一场把这么些客商也删除,再登录

[[email protected] ~]# mysql -ubruce -p -h10.20.0.231
Enter password: 
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MySQL connection id is 8
Server version: 5.5.20-log MySQL Community Server (GPL)
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome tomodify and redistribute it under the GPL v2 license
Type 'help;' or 'h' for help. Type 'c'to clear the current inputstatement.
MySQL [(none)]> show grants;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for @%                                              |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT ON*.* TO''@'%' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257'                         |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, CREATE VIEW, SHOW VIEW, CREATEROUTINE, EVENT, TRIGGER ON `test`.* TO''@'%' |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATETEMPORARY TABLES, LOCK TABLES, CREATE VIEW, SHOW VIEW, CREATEROUTINE, EVENT, TRIGGER ON `test_%`.* TO''@'%' |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
MySQL [(none)]> select user(), current_user();
+-------------------+----------------+
| user()   | current_user() |
+-------------------+----------------+
| [email protected] | @%    |
+-------------------+----------------+
1 row in set (0.00 sec)

那会儿同盟的是''@'%' 顾客

对于空顾客,私下认可有对test或test初步的数据库有权力。

以上正是MySQL验证客户权限的诀要,希望对大家的学习抱有启迪。

知识归咎因为MySQL是行使User和Host五个字段来规定客户地方的,那样就带给叁个标题,正是一个...

编辑:计算机 本文来源:奥门金沙手机娱乐网址MySQL验证客商权限的诀窍,mysql验证顾客权限

关键词: