MySQL許可權管理

2021-07-22 08:48:37 字數 1464 閱讀 4985

【%、localhost、'127.0.0.1'】

%表示允許遠端登入,localhost表示只允許本機登入,'127.0.0.1'表示只允許本機ip為'127.0.0.1'的登入。

【檢視mysql使用者許可權】

show grants for tangxinzhuan@'localhost'; // 如果使用者名稱後面不接@'localhost',則預設是使用者名稱@'%'的形式。

【刪除mysql使用者】

// 刪除了使用者,對應的許可權也沒有了!

drop user tangxinzhuan@'%';

【撤銷mysql使用者許可權】

// 撤銷使用者的所有許可權

revoke all privileges on  `nitoutiao`.* from  'tangxinzhuan'@'%';

// 撤銷使用者的grant許可權

revoke grant option on  `nitoutiao`.* from  'tangxinzhuan'@'%';

【新建mysql使用者】

create user tangxinzhuan@'%';

// 也可以建立使用者時直接設定密碼

create user tangxinzhuan@'%' identified by '123456';

【mysql使用者授權】

// 授予指定的許可權(注意:授予指定許可權之前,一定要撤銷使用者的all許可權,否則這個使用者還是all許可權。)

grant 

select, insert, update, delete, create, drop, index, alter , 

create temporary tables, create view, event, trigger, show view, create routine, alter routine, execute 

on  `nitoutiao`.* to  'tangxinzhuan'@'%';

// 只授予登入許可權

grant usage on  `nitoutiao`.* to  'tangxinzhuan'@'%';

// 授予所有許可權。all允許做任何事(和root一樣),usage只允許登入,其它什麼也不允許做。

grant all on `nitoutiao`.* to 'tangxinzhuan'@'%'

// 授予所有許可權、以及grant許可權

grant all on `nitoutiao`.* to 'tangxinzhuan'@'%' with grant option;(with grant option表示授予grant許可權,一般不授予這個許可權。)

// 一句sql實現新建mysql使用者並授權

grant all on nitoutiao.* to 'tangxinzhuan'@'%' identified by '123456' with grant option;

MySQL許可權管理

本文主要講述的是mysql grant命令的例項演示,文中的mysql grant命令的實際操作主要是在mysql 5.0 及以上的相關版本上執行,下面就是對其具體操作步驟的描述,望你在瀏覽之後會有所收穫。mysql 賦予使用者許可權命令的簡單格式可概括為 grant 許可權 on 資料庫物件 to...

mysql 許可權管理

1.新增使用者 方法一 create user wangda localhost identified by password 000000 說明 建立乙個本地的使用者,使用者名為 wangda 密碼為 000000 如果密碼為空,則 identified by password 000000 這個...

mysql許可權管理

mysqladmin u root p password leftpassword 無密碼的話直接回車 任意主機登入host換成 create user username host identified by password privileges all 代表所有許可權 表示全部的資料庫 gran...