Java最新mysql关于grant与revoke的详细教程_revoke all privileges from,如何实现分布式锁

总结

面试前的“练手”还是很重要的,所以开始面试之前一定要准备好啊,不然也是耽搁面试官和自己的时间。

我自己是刷了不少面试题的,所以在面试过程中才能够做到心中有数,基本上会清楚面试过程中会问到哪些知识点,高频题又有哪些,所以刷题是面试前期准备过程中非常重要的一点。

面试题及解析总结

三年Java开发,刚从美团、京东、阿里面试归来,分享个人面经

大厂面试场景

三年Java开发,刚从美团、京东、阿里面试归来,分享个人面经

知识点总结

三年Java开发,刚从美团、京东、阿里面试归来,分享个人面经

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

The following illustrates the syntax of the GRANT statement:

1

2

3

4

|

GRANT
privilege,[privilege],…

ON
privilege_level

TO

user
[
IDENTIFIED BY

password]

[
REQUIRE
tsl_option]

[
WITH
[GRANT_OPTION
|
resource_option]];

|

Let’s examine the GRANT statement in greater detail.

  • First, specify one or more privileges after the GRANT keyword. If you grant the user multiple privileges, each privilege is separated by a comma. (see a list of privilege in the table below).
  • Next, specify the privilege_level that determines the level at which the privileges apply. MySQL supports global ( *.*), database ( database.*), table ( database.table) and column levels. If you use column privilege level, you must specify one or a list of comma-separated column after each privilege.
  • Then, place the user that you want to grant privileges.  If user already exists, the GRANT statement modifies its privilege. Otherwise, the GRANT statement creates a new user. The optional clauseIDENTIFIED BY allows you set a new password for the user*.*
  • After that, you specify whether the user has to connect to the database server over a secure connection such as SSL, X059, etc.
  • Finally, the optional WITH GRANT OPTION clause allows you to grant other users or remove from other users the privileges that you possess. In addition, you can use the WITH clause to allocate MySQL database server’s resource e.g., to set how many connections or statements that the user can use per hour. This is very helpful in the shared environments such as MySQL shared hosting.

Notice that in order to use the GRANT statement, you must have the GRANT OPTION privilege and the privileges that you are granting. If the [read\_only]( )system variable is enabled, you need to have the SUPERprivilege to execute the GRANT statement.

Let’s practice with some examples of using MySQL GRANT statement to have a better understanding.

MySQL GRANT examples

For example, the following 
CREATE USER
 statement creates a new super user account.

CREATE USERsuper@localhostIDENTIFIED BY’dolphin’;

To display the privileged assigned to super@localhost user, you use SHOW GRANTS statement.

SHOWGRANTSFORsuper@localhost;

如果未曾赋予用户权限,则会提示:

1

2

3

4

5

6

|

±------------------------------------------+

|

Grants

for

super@localhost
                |

±------------------------------------------+

|

GRANT

USAGE

ON
*.*

TO
super@localhost
|

±------------------------------------------+

1

row

in

set
(0.00
sec)

|

To grant all privileges to the super@localhost user account, you use the following statement.Note that USAGE privilege means no privileges in MySQL.

GRANTALLON*.*TO’super’@'localhost’WITH GRANT OPTION;、//赋予本地super用户超级权限(含grant)

The

权限包含有:

SELECT /INSERT /UPDATE / DELETE / DROP / CREATE / CREATE USER / ALTER / ALTER ROUTINE (使用alter procedure和drop procedure) / CREATE ROUTINE (使用create procedure) / CREATE

TEMPORARY TABLES (使用create temporary table)/ CREATE VIEW / EXECUTE (使用call和存储过程) / EVENT / FILE (使用select into outfile 和 load data infile) / GRANT OPTION (可以使用grant和revoke) / ALL / ALL PRIVILEGES / INDEX (可以使用create index和drop index) / LOCK TABLES (锁表) / PROCESS (使用show full processlist) / RELOAD (使用flush) / REPLICATION CLIENT (服务器位置访问) / REPLICATION SLAVE (由复制从属使用) / SHOW DATABASES / SHOW VIEW / SHUT DOWN (使用mysqladmin shutdown 来关闭mysql)/ SUPER / USAGE (无访问权限)

ALL PRIVILEGES; //等同于All

数据对象:

*.*  所有库和所有表。

databaseName.*  某个库中的所有表

databaseName.tableName   某个库中某个表

设置权限时必须给出一下信息

1,要授予的权限

2,被授予访问权限的数据库或表

3,用户名(及主机?有时候无需主机也可以)

grant和revoke可以在几个层次上控制访问权限

1,整个服务器,使用 grant ALL  和revoke  ALL

2,整个数据库,使用on  database.*

3,特点表,使用on  database.table

4,特定的列

5,特定的存储过程

user表中host列的值的意义

%              
匹配所有主机

localhost    
localhost不会被解析成IP地址,直接通过UNIXsocket连接

127.0.0.1      
会通过TCP/IP协议连接,并且只能在本机访问;

::1                 
::1就是兼容支持ipv6的,表示同ipv4的127.0.0.1

使用案例:

grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。

grant select, insert, update, delete on testdb.* to common_user@’%’

grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。

grant 创建、修改、删除 MySQL 数据表结构权限。

grant create on testdb.* to developer@’192.168.0.%’;

grant alter on testdb.* to developer@’192.168.0.%’;

grant drop on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 外键权限。

grant references on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 临时表权限。

grant create temporary tables on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 索引权限。

grant index on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 视图、查看视图源代码 权限。

grant create view on testdb.* to developer@’192.168.0.%’;

grant show view on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 存储过程、函数 权限。

grant create routine on testdb.* to developer@’192.168.0.%’; – now, can show procedure status

grant alter routine on testdb.* to developer@’192.168.0.%’; – now, you can drop a procedure

grant execute on testdb.* to developer@’192.168.0.%’;

grant 作用在整个 MySQL 服务器上:

grant select on *.* to dba@localhost; – dba 可以查询 MySQL 中所有数据库中的表。

grant all on *.* to dba@localhost; – dba 可以管理 MySQL 中的所有数据库

grant 作用在单个数据库上:

grant select on testdb.* to dba@localhost; – dba 可以查询 testdb 中的表。

grant 作用在单个数据表上:

grant select, insert, update, delete on testdb.orders to dba@localhost;

grant 作用在表中的列上:

grant select(id, se, rank) on testdb.apache_log to dba@localhost;

grant 作用在存储过程、函数上:

grant execute on procedure testdb.pr_add to ’dba’@’localhost’

grant execute on function testdb.fn_add to ’dba’@’localhost’

注意:修改完权限以后 一定要刷新服务,或者重启服务,刷新服务用:FLUSH PRIVILEGES

同理:revoke英文文档如下:

Introduction to the MySQL REVOKE Statement

In order to revoke privileges from a user account, you use the MySQL REVOKE statement. MySQL allows you to revoke one or more privileges or all privileges from a user.

The following illustrates the syntax of revoking specific privileges from a user:

1

2

3

4

|

REVOKE
   privilege_type
[(column_list)]

[,
priv_type
[(column_list)]]…

ON
[object_type]
privilege_level

知其然不知其所以然,大厂常问面试技术如何复习?

1、热门面试题及答案大全

面试前做足功夫,让你面试成功率提升一截,这里一份热门350道一线互联网常问面试题及答案助你拿offer

2、多线程、高并发、缓存入门到实战项目pdf书籍

3、文中提到面试题答案整理

4、Java核心知识面试宝典

覆盖了JVM 、JAVA集合、JAVA多线程并发、JAVA基础、Spring原理、微服务、Netty与RPC、网络、日志、Zookeeper、Kafka、RabbitMQ、Hbase、MongoDB 、Cassandra、设计模式、负载均衡、数据库、一致性算法 、JAVA算法、数据结构、算法、分布式缓存、Hadoop、Spark、Storm的大量技术点且讲解的非常深入

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

、Zookeeper、Kafka、RabbitMQ、Hbase、MongoDB 、Cassandra、设计模式、负载均衡、数据库、一致性算法 、JAVA算法、数据结构、算法、分布式缓存、Hadoop、Spark、Storm的大量技术点且讲解的非常深入**

[外链图片转存中…(img-hPETYhyT-1715408905604)]

[外链图片转存中…(img-CiBb47h2-1715408905604)]

[外链图片转存中…(img-4opV2Abj-1715408905605)]

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值