MySQL基本操作---數據控制語言(DCL)

###數據控制語言(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`
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章