MySQL基本操作 資料控制語言 DCL

2021-09-06 22:54:58 字數 1492 閱讀 2351

###資料控制語言(dcl)

- 檢視授權:

- 格式:`show grants [for 'user'@'host'];`

- 示例:`show grants for 'root'@'localhost';`

- 說明:檢視當前登入使用者授權時可以不指定使用者及主機

- 建立使用者:

- 格式:`create user 'user'@'host' identified by 'password';`

- 示例:`create user 'test'@'10.8.156.%' identified by '123456';`

- 說明:%表示萬用字元,任意的

- 使用者授權:

- 格式:`grant 許可權 privileges on 庫名.表名 to 'user'@'host' identified by 'password';`

- 示例:`grant all privileges on *.* to 'test'@'10.8.156.%' identified by '123456';`

- 說明:許可權可以是select、delete、insert、update等,all表示所有許可權;*表示所有

- 重新整理許可權:`flush privileges;`

- 取消授權:

- 格式:`revoke 許可權 privileges on 庫名.表名 from 'user'@'host';` 

- 示例:`revoke delete privileges on test.* from 'test'@'10.8.156.%';`

- 說明:收回當前區域網內的test使用者在test庫下所有的表的刪除許可權

- 刪除使用者:

- 格式:`drop user 'user'@'host';`

- 示例:`drop user 'test'@'10.8.156.%';`

- linux下遠端登入:

- `bind-address=127.0.0.1` 改為:`bind-address=0.0.0.0`

- 新增指定使用者在指定主機的操作許可權:

```mysql

grant all privileges on *.* to 'root'@'%' identified by '123456';

```### 備份與恢復

- 備份:

- 說明:就是將資料庫中的資料(sql語句)儲存到乙個檔案中

- 示例:`mysqldump -uroot -p test

>

test.sql`

- 恢復:

- 說明:將儲存sql語句的檔案解析,挨個執行其中的sql語句

- 示例:`mysql -uroot -p test < test.sql`

MySQL基本操作 資料操作

刪除資料 更新字段 1.插入指定字段值 insert into 表名 字段列表 values 對應字段值列表 2.向表中所有字段插入資料 insert into 表名 values 按表結構寫對應資料 insert into my teacher values liwei 20 1.查詢表中全部資料...

mysql資料控制語言 Mysql資料控制語言

mysql資料控制語言 1.資料控制語言 使用者管理 使用者資訊的儲存位置 mysql中的使用者,都儲存在mysql系統的系統資料庫 mysql 中。2.建立使用者 create user 使用者名稱 允許登入的位置 identified by 密碼 舉例 3.刪除使用者 drop user 使用者...

MySQL基本操作 資料庫和表

資料庫的操作 mysql中,資料庫的基本操作有 建立 檢視 選擇以及刪除4種。mysql表的操作 建立表語法 create table table name column name,column type example create table if not exists runoob tbl r...