MySQL 建立使用者和設定許可權

2021-08-24 17:45:58 字數 1612 閱讀 4149

1.建立使用者和設定許可權:create user和grant命令

grant 和revoke命令分別授予和取消mysql使用者的許可權

create user user_info

identified by [password] password |identified with [auth_plugin] [as auth_string]

方括號中子句是可選的。user_info->>user_name@hostname 其中hostname可選,而user_name是mysql中登入的使用者名稱

grant privileges [columns]

on item

to user_info

[identified by password]|identified with [auth_plugin] [as auth_string]]

[require ssl_options]

[with [grant option| limit_options]]

revoke命令與grant相反,它用來從乙個使用者收回許可權,在語法上與grant十分相似

revoke privileges 

on item

from user_name

如果已經給出了with grant option 子句,可以按照啊如下方式撤銷許可權

revoke all privileges,grant option 

from user_name

2.使用grant 和revoke例項

要建立乙個管理員,可以輸入如下命令

grant all

on *.*

to 'fred' identified by 'mnb123'

with grant option;

以上命令授予了使用者fred,密碼未mnb123的使用者使用所有資料庫的所有許可權以及雲溪向其他人授予這些許可權

如果不希望使用者在系統中存在,可以按以下方式撤銷授權

revoke all privilegess,grant option

from 'fred';

現在,可以按以下方式是建立乙個沒有任何許可權的使用者

grant usage 

on book.*

to 'sally'@'localhost' identified by 'magic123'

然後可以按照以下方式授予適當許可權

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

on books.*

to 'sally'@'localhost';

注意:要授予許可權,並不需要指定密碼

如果認為sally的許可權過高,可以按照以下方式撤銷所有許可權

revoke all

on books.*

from 'sally'@'localhost';

現在,對revokr和grant命令是否有了初步了解了?

MySQL建立使用者並設定許可權

需求 資料庫中建立了乙個檢視,在mysql中新增使用者,並給指定使用者分配查詢select許可權。開啟cmd,執行一下命令連線資料庫 mysql h localhost p 3306 u root p 回車並資料密碼,即可進入mysql use mysql tempuser表示你要建立的使用者名稱,...

MYSQL建立普通使用者和設定許可權

mysql uroot p 建立使用者需要root擴充套件 其中 u是賬號,小寫的p是密碼,h是ip位址,大寫的p是埠 mysql uroot p123456 h127.0.0.1 p3306use mysql 賬戶資訊全部保留在myqsl資料庫中擴充套件 檢視當前mysql資料庫裡有多少使用者,建...

mysql 使用者管理和許可權設定

mysql庫中user,db,host,tables priv,columns priv 5張表涉及到許可權。1,建立使用者 select host,user,password from user where user guest 賦權 a,grant select,insert,update,de...