1. 程式人生 > >MYSQL 建立使用者並授權

MYSQL 建立使用者並授權

通過CREATE USER命令進行建立使用者
CREATE USER '[email protected]' [IDENTIFIED BY 'PASSWORD'] 其中密碼是可選項;
例子:CREATE USER '[email protected]' IDENTIFIED BY "123";
說明:該方法創建出來的使用者只有連線資料庫的許可權,需要後續繼續授權;

=========================================

查詢、插入、更新、刪除 資料庫中所有表資料的權利。
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 create on testdb.* to
[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 references on testdb.* to [email protected]'192.168.0.%';

操作臨時表許可權。
grant create temporary tables on testdb.* to [email protected]
'192.168.0.%';

操作索引許可權。
grant index on testdb.* to [email protected]'192.168.0.%';
 
操作檢視、檢視檢視原始碼許可權
grant create view on testdb.* to [email protected]'192.168.0.%';
grant show view on testdb.* to [email protected]'192.168.0.%';
 

操作儲存過程、函式 許可權
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 all privileges on testdb to [email protected]'localhost'
其中,關鍵字 “privileges” 可以省略


管理所有資料庫的許可權。
grant all on *.* to [email protected]'localhost'

檢視當前使用者(自己)許可權:
show grants;
 
檢視其他使用者許可權:
show grants for [email protected];

撤銷已經賦予給使用者許可權的許可權。
revoke 跟 grant 的語法差不多,只需要把關鍵字 “to” 換成 “from” 即可:
grant all on *.* to [email protected];

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

請記得刷新系統許可權表;

flush privileges;