SQL语句的分类

  1. DDL(Data Definition Languages)语句:数据定义语言。这些语句定义了不同的数据段、

    数据库、表、列、索引等数据库对象的定义。常用的语句关键字主要包括create、drop、alter

    等。
  2. DML(Data Manipulation Language)语句:数据操纵语句,用于添加、删除、更新和查

    询数据库记录,并检查数据完整性,常用的语句关键字主要包括insert、delete、udpate 和

    select 等。
  3. DCL(Data Control Language)语句:数据控制语句,用于控制不同数据段直接的许可和

    访问级别的语句。这些语句定义了数据库、表、字段、用户的访问权限和安全级别。主要的

    语句关键字包括grant、revoke 等。

DCL语句

DCL 语句主要是DBA 用来管理系统中的对象权限时所使用,一般的开发人员很少使用。下面

通过一个例子来简单说明一下。

创建一个数据库用户plf,具有对plf数据库中所有表的SELECT/INSERT 权限:

mysql> grant select,insert on plf.* to 'plf'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> quit
Bye [root@mysql ~]# mysql -uplf -p123456 -h 192.168.3.100
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.37 Source distribution Copyright (c) 2000, 2017, 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> use mysql;
ERROR 1044 (42000): Access denied for user 'plf'@'%' to database 'mysql'
mysql> use plf
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed

由于权限变更,需要将 plf 的权限变更,收回 INSERT,只能对数据进行 SELECT 操作,这时我们需要使用root账户进行上述操作:

mysql> revoke insert on plf.* from 'plf'@'%';
Query OK, 0 rows affected (0.00 sec) mysql> quit
Bye [root@mysql ~]# mysql -uplf -p123456 -h 192.168.3.100
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.6.37 Source distribution Copyright (c) 2000, 2017, 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> use plf
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> show tables;
+---------------+
| Tables_in_plf |
+---------------+
| dept |
| emp |
| hk_info |
| log_info |
| user_info |
+---------------+
5 rows in set (0.00 sec) mysql> insert into dept values(7,'plf');
ERROR 1142 (42000): INSERT command denied to user 'plf'@'192.168.3.100' for table 'dept'
mysql> select*from dept;
+--------+----------+
| deptno | deptname |
+--------+----------+
| 1 | tech |
| 2 | sale |
| 3 | hr |
| 5 | fin |
+--------+----------+
4 rows in set (0.00 sec)

以上例子中的grant和revoke分别授出和收回了用户plf的部分权限,达到了我们的目的,关于权限的更多内容,将会在第4篇中详细介绍。

MySQL操作之DCL的更多相关文章

  1. 学习笔记:MySQL操作初步

    对数据库的操作:SQL语言 一:SQL:Structured Query Language,结构化查询语言! 二:DDL:Data Definition Language,数据定义语言 三:DML:D ...

  2. Mysql操作初级

    Mysql操作初级 本节内容 数据库概述 数据库安装 数据库操作 数据表操作 表内容操作 1.数据库概述 数据库管理系统叫做DBMS 1.什么是数据库 ? 答:数据的仓库,如:在ATM的示例中我们创建 ...

  3. python学习道路(day12note)(mysql操作,python链接mysql,redis)

    1,针对mysql操作 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass'); 设置密码 update user set password ...

  4. ecshop的Mysql操作类

    摘要,这是直接摘抄的ecshop的mysql操作类:不过他这里的缓存是用的文件缓存,我们如果想直接使用,可以替换成memcache的或者redis的! <?php /** * ECSHOP MY ...

  5. shell执行mysql操作

    http://ully.iteye.com/blog/1226494 http://www.jb51.net/article/55207.htm shell执行mysql操作 mysql  -hhos ...

  6. mysql操作类库--摘抄

    <!--?php /** +---------------------------------- * MySQL操作类库 +---------------------------------- ...

  7. 第一篇:Mysql操作初级

    Mysql操作初级   Mysql操作初级 本节内容 数据库概述 数据库安装 数据库操作 数据表操作 表内容操作 1.数据库概述 数据库管理系统叫做DBMS 1.什么是数据库 ? 答:数据的仓库,如: ...

  8. Mysql 操作手册

    mysql操作手册 版本:5.6.16mysql linux安装基本步骤:#rpm -e --nodeps mysql-lib-5.1.*#rpm -ivh mysql-server#rpm -ivh ...

  9. Python 第九篇:队列Queue、生产者消费者模型、(IO/异步IP/Select/Poll/Epool)、Mysql操作

    Mysql操作: grant select,insert,update,delete on *.* to root@"%" Identified by "123456&q ...

随机推荐

  1. kettel路径配置

    背景 kettel 8.3 jdk13.0.1 jre1.8.0 配置 PENTAHO_JAVA_HOME:C:\Program Files (x86)\Java\jre1.8.0_241 JAVA_ ...

  2. bfs迷宫

    链接:https://ac.nowcoder.com/acm/contest/338/BSleeping is a favorite of little bearBaby, because the w ...

  3. 解决1130-host'192.168.2.137'is not allowed to connect to this mysql server报错问题

    连接数据库服务器出现1130-host'192.168.2.137'is not allowed to connect to this mysql server错误, 这个问题是因为在数据库服务器中的 ...

  4. 「HNOI/AHOI2018」游戏

    传送门 Luogu 解题思路 这是一道 \(O(n^2)\) 暴力加上 \(\text{random_shuffle}\) 优化 什么鬼 就可以 \(\text{AC}\) 的题. 但还是要讲一下 \ ...

  5. MyBatis-Plus学习笔记(2):代码生成器

    AutoGenerator 是 MyBatis-Plus 的代码生成器,通过 AutoGenerator 可以快速生成 Entity.Mapper.Mapper XML.Service.Control ...

  6. [CISCN2019 华北赛区 Day1 Web1]Dropbox

    0x01 前言 通常我们在利用反序列化漏洞的时候,只能将序列化后的字符串传入unserialize(),随着代码安全性越来越高,利用难度也越来越大.但在不久前的Black Hat上,安全研究员Sam ...

  7. 5_7 丑数(UVa136)<priority_queue的使用>

    Ugly Number的定义为:该数之质因数必须为2,3或5,当然了,依照惯例,1也算是Ugly Number.在此列举一串数列:1,2,3,4,5,6,8,9,10,12,15这些就是前11个Ugl ...

  8. Bugku-CTF社工篇之简单的个人信息收集

  9. Informatica PowerCenter 常用转换组件一览表

    原文地址:https://blog.csdn.net/yongjian1092/article/details/52176018 转换类型: 积极转换(Active):可以更改通过它来传递的数据行数, ...

  10. POJ 1204 Word Puzzles(AC自动机)

    这题的数据卡在,如下: 5 5 3 ABCDE FGHIJ KLMNO PQRST UVWXY PQR RS RST puzzle中间的行中可以包含要查询的多个单词.这个问题很好解决,SearchDf ...