1. 程式人生 > >MySQL資料庫授權命令

MySQL資料庫授權命令

本文例項,運行於 MySQL 5.0 及以上版本。

MySQL 賦予使用者許可權命令的簡單格式可概括為:

grant 許可權 on 資料庫物件 to 使用者
 

一、grant 普通資料使用者,查詢、插入、更新、刪除 資料庫中所有表資料的權利。

grant select on testdb.* to [email protected]'%'
grant insert on testdb.* to [email protected]'%'
grant update on testdb.* to [email protected]'%'
grant delete on testdb.* to 
[email protected]
'%'

或者,用一條 MySQL 命令來替代:

grant select, insert, update, delete on testdb.* to [email protected]'%'

二、grant 資料庫開發人員,建立表、索引、檢視、儲存過程、函式。。。等許可權。

grant 建立、修改、刪除 MySQL 資料表結構許可權。

grant create on testdb.* to develope[email protected]'192.168.0.%';
grant alter  on testdb.* to [email protected]
'192.168.0.%'; grant drop on testdb.* to [email protected]'192.168.0.%';
 

grant 操作 MySQL 外來鍵許可權。

grant references on testdb.* to [email protected]'192.168.0.%';

grant 操作 MySQL 臨時表許可權。

grant create temporary tables on testdb.* to [email protected]'192.168.0.%';

grant 操作 MySQL 索引許可權。

grant index on testdb.* to 
[email protected]
'192.168.0.%';

grant 操作 MySQL 檢視、檢視檢視原始碼 許可權。

grant create view on testdb.* to [email protected]'192.168.0.%';
grant show   view on testdb.* to [email protected]'192.168.0.%'; 

grant 操作 MySQL 儲存過程、函式 許可權。

grant create routine on testdb.* to [email protected]'192.168.0.%'; -- now, can show procedure status
grant alter  routine on testdb.* to [email protected]'192.168.0.%'; -- now, you can drop a procedure
grant execute        on testdb.* to [email protected]'192.168.0.%'; 

三、grant 普通 DBA 管理某個 MySQL 資料庫的許可權。

grant all privileges on testdb to [email protected]'localhost'

其中,關鍵字 “privileges” 可以省略。

四、grant 高階 DBA 管理 MySQL 中所有資料庫的許可權。

grant all on *.* to [email protected]'localhost'

五、MySQL grant 許可權,分別可以作用在多個層次上。

1. grant 作用在整個 MySQL 伺服器上:

grant select on *.* to [email protected]; -- dba 可以查詢 MySQL 中所有資料庫中的表。
grant all    on *.* to [email protected]; -- dba 可以管理 MySQL 中的所有資料庫。

2. grant 作用在單個數據庫上:

grant select on testdb.* to [email protected]; -- dba 可以查詢 testdb 中的表。

3. grant 作用在單個數據表上:

grant select, insert, update, delete on testdb.orders to [email protected];

這裡在給一個使用者授權多張表時,可以多次執行以上語句。例如:

grant select(user_id,username) on smp.users to [email protected]'%' identified by '123345';
grant select on smp.mo_sms to [email protected]'%' identified by '123345';
4. grant 作用在表中的列上:
grant select(id, se, rank) on testdb.apache_log to [email protected]; 

5. grant 作用在儲存過程、函式上:

grant execute on procedure testdb.pr_add to 'dba'@'localhost'
grant execute on function testdb.fn_add to 'dba'@'localhost' 

六、檢視 MySQL 使用者許可權

檢視當前使用者(自己)許可權:

show grants; 

檢視其他 MySQL 使用者許可權:

show grants for [email protected];


七、撤銷已經賦予給 MySQL 使用者許可權的許可權。

revoke 跟 grant 的語法差不多,只需要把關鍵字 “to” 換成 “from” 即可:

grant  all on *.* to   [email protected];
revoke all on *.* from [email protected];

八、MySQL grant、revoke 使用者許可權注意事項

1. grant, revoke 使用者許可權後,該使用者只有重新連線 MySQL 資料庫,許可權才能生效。

2. 如果想讓授權的使用者,也可以將這些許可權 grant 給其他使用者,需要選項 “grant option“

grant select on testdb.* to [email protected] with grant option;

這個特性一般用不到。實際中,資料庫許可權最好由 DBA 來統一管理。

*************************************************************************************************

遇到 SELECT command denied to user '使用者名稱'@'主機名' for table '表名' 這種錯誤,解決方法是需要把吧後面的表名授權,即是要你授權核心資料庫也要。

我遇到的是SELECT command denied to user 'my'@'%' for table 'proc',是呼叫儲存過程的時候出現,原以為只要把指定的資料庫授權就行了,什麼儲存過程、函式等都不用再管了,誰知道也要把資料庫mysql的proc表授權

*************************************************************************************************

mysql授權表共有5個表:user、db、host、tables_priv和columns_priv。

授權表的內容有如下用途:
user表
user表列出可以連線伺服器的使用者及其口令,並且它指定他們有哪種全域性(超級使用者)許可權。在user表啟用的任何許可權均是全域性許可權,並適用於所有資料庫。例如,如果你啟用了DELETE許可權,在這裡列出的使用者可以從任何表中刪除記錄,所以在你這樣做之前要認真考慮。

db表
db表列出資料庫,而使用者有許可權訪問它們。在這裡指定的許可權適用於一個數據庫中的所有表

host表
host表與db表結合使用在一個較好層次上控制特定主機對資料庫的訪問許可權,這可能比單獨使用db好些。這個表不受GRANT和REVOKE語句的影響,所以,你可能發覺你根本不是用它。

tables_priv表
tables_priv表指定表級許可權,在這裡指定的一個許可權適用於一個表的所有列

columns_priv表
columns_priv表指定列級許可權。這裡指定的許可權適用於一個表的特定列

個性簽名:做要做好,做到不三不四不如不做。

相關推薦

MySQL資料庫授權命令

本文例項,運行於 MySQL 5.0 及以上版本。 MySQL 賦予使用者許可權命令的簡單格式可概括為: grant 許可權 on 資料庫物件 to 使用者  一、grant 普通資料使用者,查詢、插入、更新、刪除 資料庫中所有表資料的權利。 grant select on

MySQL資料庫常用命令大全

                                常用命令大全(持續更新) show databases;顯示所有資料庫

linux系統下操作mysql資料庫常見命令

一. 備份資料庫(如: test): ①可直接進入後臺即可.(MySQL的預設目錄:/var/lib/mysql ) ②輸入命令: [[email protected] mysql]# mysqldump -u root -p test>/home/bak/201

MySQL資料庫管理(命令)

第一次接觸mysql,記錄一下 學習資料:https://www.cnblogs.com/GarveyCalvin/p/4297282.html 1.檢視當前有哪些資料庫 show databases; 2.建立資料庫 create database xxxxx;

mysql資料庫常用命令(一)

– 資料庫的操作 -- 連結資料庫 mysql -uroot -p mysql -uroot -pmysql -- 退出資料庫 exit/quit/ctrl+d -- sql語句最後需要有分號;結尾 -- 顯示資料庫版本 select version()

Linux下操作MySQL資料庫常用命令

目錄 5.查詢表 9.退出 1.連線資料庫 mysql -u -root -p 輸入密碼 2.檢視資料庫 show databases;  3.開啟資料庫

MYSQL資料庫常用命令

MySQL是一個關係型資料庫管理系統,由瑞典MySQL AB 公司開發,目前屬於 Oracle 旗下產品。MySQL 最流行的關係型資料庫管理系統,在 WEB 應用方面MySQL是最好的 RDBMS (Relational Database Management

MySQl資料庫簡單命令之dcl

SQL (結構化 Structured 查詢 Query 語言 Language)分類DDL(資料定義語言) 表的定義、使用者的定義... create drop alterDML(資料操控語言) 對資料的增加、修改、刪除、查詢 insert update delete selectDCL(資料控制語言) g

mysql資料庫匯出命令

(1)用mysqldump命令列:mysqldump -u 使用者名稱 -p 資料庫名 > 資料庫名.sql eg: mysqldump -uroot -p abc >abc.sql 匯出資料庫abc到abc.sql檔案 (2)用mysql命令列:mysql

MySql資料庫常用命令總結(全)

一、資料庫級命令 1. 資料庫連線 命令:mysql -h主機地址 -u使用者名稱 -p使用者密碼 –port=3307 1、找到安裝目錄bin, 進入該工作目錄,鍵入該命令mysql -u root -p,提示輸入密碼,使用者名稱前可以有空格也可以沒

Mysql資料庫操作命令

mysql> create table imgtable( -> id int unsigned primary key auto_increment not null, -> username varchar(50) not null, -> userpass

MYSQL資料庫----刪除命令

drop,truncate,delete區別    1、drop (刪除表):刪除內容和定義,釋放空間。簡單來說就是把整個表去掉.以後要新增資料是不可能的,除非新增一個表。       drop語句將刪除表的結構被依賴的約束(constrain),觸發器(trigger)索引(

MySQL資料庫mysqldump命令備份異常的一個案例

MySQL中的命令列mysqldump做為常用的資料備份工具,雖說效能稍差,但優在易於呼叫,從長期應用的情況來看其表現也相當穩定,並且老實講MySQL資料庫下邏輯備份確實沒有太多選擇,因此mysqldump應用極為廣泛,三思本人也是經常使用這個命令倒騰資料,整體感覺是個挺美

mysql資料庫常用命令總結

本文主要記錄一些mysql日常使用的命令,供以後查詢。 1.更改root密碼 mysqladmin -uroot password 'yourpassword'1 2.遠端登陸mysql伺服器 mysql -uroot -p -h192.168.137.10 -P330

mysql資料庫命令列下常用命令的操作(增、刪、改、查)和資料型別

identified by "";   第四招: 操作資料庫   登入到mysql中,然後在mysql的提示符下執行下列命令,每個命令以分號結束。   1、 顯示資料庫列表。   show databases;   預設有兩個資料庫:mysql和 test。 mysql庫存放著mysql的系統和使

MySQL資料庫grant授權命令

MySQL資料庫grant授權命令 製作人:全心全意 grant授權命令的使用 grant授權命令使用語法: grant 許可權 on 資料庫物件 to 使用者   許可權:   select:檢視資料庫表資料許可權   insert:插入資料庫表資料許可權   upd

Linux系統使用mysql命令建立資料庫授權命令

登入Linux伺服器登入MYSQL:mysql -u root -p一、指令碼建立資料庫demodb,並制定預設的字符集是utf8mb4。CREATE DATABASE demodb DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_genera

命令列下建立MySQL資料庫與建立使用者以及授權

先以root使用者登入mysql:C:\Users\XXX>mysql -u root -p輸入密碼後登入,接下來操作如下:1、建立資料庫語法:create schema [資料庫名稱] default character set utf8 collate utf8_g

命令列連線 MySQL 資料庫並進行授權

登入 MYSQL 資料庫 在 win10 ,需要開啟管理員的命令列視窗(Windows PowerShell(管理員)A),沒有管理員許可權會導致登入失敗。 執行命令: mysql -hloc

MySQL授權命令grant的使用方法

log 源代碼 簡單 更新 ron temporary drop all ces 本文實例,運行於 MySQL 5.0 及以上版本。 MySQL 賦予用戶權限命令的簡單格式可概括為: grant 權限 on 數據庫對象 to 用戶 一、grant 普通數據用戶,查