記錄的增刪改查和權限管理


主要內容:

  一、插入數據--insert

  二、更新數據--update

  三、刪除數據--delete

  四、權限管理

 

1️⃣  插入數據--insert

 1、插入完整的數據 語法一(指定字段插入): insert into 表名(字段1,字段2,...字段n) values(值1,值2,值3...值n); 語法二(整體插入): insert into 表名 values(值1,值,...值n); 2、插入多條記錄 語法: insert into 表名 values (值1,值2,值3...), (值1,值2,值3...), (值1,值2,值3...); 3、插入查詢結果 語法: insert into 表名(字段1,字段2,...) select(字段1,字段2,字段3...) from 表2 where ...;

 

2️⃣  更新數據--update

語法: update 表名 set 字段1=值1, 字段2=值2, where condition; 例如:update mysql.user set password=password('123') where user='root' and host='localhost';

 

3️⃣  刪除數據--delete 

 語法: delete from 表名 where condition; 示例: delete from mysql.user where password='';

 

4️⃣  權限管理 

  1、授權表 

user #該表放行的權限,針對:所有數據,所有庫下所有表,以及表下的所有字段
db #該表放行的權限,針對:某一數據庫,該數據庫下的所有表,以及表下的所有字段
tables_priv #該表放行的權限。針對:某一張表,以及該表下的所有字段
columns_priv #該表放行的權限,針對:某一個字段

  2、創建用戶

create user 'cc'@'1.1.1.1' identified by '123'; create user 'cc'@'192.168.1.%' identified by '123'; create user 'cc'@'%' identified by '123';

  3、授權:對文件夾,對文件,對文件某一字段的權限

查看幫助:help grant 常用權限有:select,update,alter,delete all可以代表除了grant之外的所有權限 
#針對所有庫的授權:*.*
grant select on *.* to 'cc1'@'localhost' identified by '123'; #只在user表中可以查到cc1用戶的select權限被設置為Y

#針對某一數據庫:db1.*
grant select on db1.* to 'cc2'@'%' identified by '123'; #只在db表中可以查到cc2用戶的select權限被設置為Y

#針對某一個表:db1.t1
grant select on db1.t1 to 'cc3'@'%' identified by '123';  #只在tables_priv表中可以查到cc3用戶的select權限

#針對某一個字段:
mysql> select * from t3; +------+-------+------+
| id   | name  | age  |
+------+-------+------+
|    1 | cc1   |   18 |
|    2 | cc2   |   19 |
|    3 | cc3   |   29 |
+------+-------+------+

 grant select (id,name),update (age) on db1.t3 to 'cc4'@'localhost' identified by '123'; 

  4、可以在tables_priv和columns_priv中看到相應的權限

mysql> select * from tables_priv where user='cc4'\G *************************** 1. row *************************** Host: localhost Db: db1 User:cc4 Table_name: t3 Grantor: root@localhost Timestamp: 0000-00-00 00:00:00 Table_priv: Column_priv: Select,Update row in set (0.00 sec) mysql> select * from columns_priv where user='cc4'\G *************************** 1. row *************************** Host: localhost Db: db1 User:cc4 Table_name: t3 Column_name: id Timestamp: 0000-00-00 00:00:00 Column_priv: Select *************************** 2. row *************************** Host: localhost Db: db1 User: cc4 Table_name: t3 Column_name: name Timestamp: 0000-00-00 00:00:00 Column_priv: Select *************************** 3. row *************************** Host: localhost Db: db1 User: cc4 Table_name: t3 Column_name: age Timestamp: 0000-00-00 00:00:00 Column_priv: Update rows in set (0.00 sec)

 

5️⃣刪除權限

revoke select on db1.* to 'alex'@'%';

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM