MySQL建立使用者和授權

2021-10-18 03:39:05 字數 2338 閱讀 5846

我們知道我們的最高許可權管理者是root使用者,它擁有著最高的許可權操作。包括select、update、delete、update、grant等操作。那麼一般情況在公司之後dba工程師會建立乙個使用者和密碼,讓你去連線資料庫的操作,並給當前的使用者設定某個操作的許可權(或者所有許可權)。那麼這時就需要我們來簡單了解一下:

如何建立使用者和密碼

給當前的使用者授權

設定和更改使用者密碼

移除當前使用者的許可權

一. 建立使用者

命令:

create user 'username'@'host' identified by 'password'

;

說明:

例子:

create user 'dog'@'localhost' identified by '123456'

;create user 'pig'@'192.168.1.101_' idendified by '123456'

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

;create user 'pig'@'%' identified by ''

;create user 'pig'@'%'

;

二. 授權:

命令:

grant privileges on databasename.tablename to 'username'@'host'
說明:

例子:

grant select

, insert on test.user to 'pig'@'%'

;grant all on *

.* to 'pig'@'%'

;grant all on maindataplus.

* to 'pig'@'%'

;

注意:

用以上命令授權的使用者不能給其它使用者授權,如果想讓該使用者可以授權,用以下命令:

grant privileges on databasename.tablename to 'username'@'host' with grant option;
三.設定與更改使用者密碼

命令:

set password for

'username'@'host' = password(

'newpassword'

);

如果是當前登陸使用者用:

set password = password(

"newpassword"

);

例子:

set password for

'pig'@'%' = password(

"123456"

);

四. 撤銷使用者許可權

命令:

revoke privilege on databasename.tablename from

'username'@'host'

;

說明:

privilege, databasename, tablename:同授權部分

例子:

revoke select on *.*

from

'pig'@'%'

;

注意:

假如你在給使用者』pig』@』%『授權的時候是這樣的(或類似的):grant select on test.user to 『pig』@』%』,則在使用revoke select on . from 『pig』@』%』;命令並不能撤銷該使用者對test資料庫中 user 表的 select 操作。相反,如果授權使用的是grant select on . to 『pig』@』%』;則revoke select on test.user from 『pig』@』%』;命令也不能撤銷該使用者對 test 資料庫中 user 表的 select 許可權。

具體資訊可以用命令 show grants for 『pig』@』%』; 檢視。

五.刪除使用者

命令:

drop user 'username'@'host'

;

其他
# instead of skip-networking the default is now to listen only on

# localhost which is more compatible and is not less secure.

# bind-address = 127.0.0.1 #注釋掉這一行就可以遠端登入了

MYSQL建立使用者和授權

登入mysql 有root許可權 mysql u root p 密碼 建立使用者 mysql mysql insert into mysql.user host,user,password,ssl cipher,x509 issuer,x509 sub ject values localhost p...

Mysql建立使用者和授權

假設使用者名稱是yanzi,密碼是 123456 1.建立使用者 create user yanzi identified by 123456 2.授權 左邊的星號表示database,右邊的星號是table.grant select,insert,update,delete on to yanzi...

mysql 建立使用者和授權

create user username host identified by password create user dog localhost identified by 123456 create user pig 192.168.1.101 idendified by 123456 cre...