MySQL8使用者管理

2021-10-23 08:37:11 字數 1304 閱讀 9969

mysql> create user 'user1'@'localhost' identified by '123456';

identified by 後面是密碼,直接寫就可,不需再加password()函式。

使用剛剛建立的使用者登入,然後執行show databases會發現只有乙個名為information_schema的資料庫。因為該使用者沒有其他資料庫的許可權。此時嘗試去建立資料庫也不會成功。

mysql>

create

database user1db;

error 1044

(42000

): access denied for

user

'user1'@'localhost' to database 'user1db'

接下來切回root使用者對其授權:

mysql>

create

database user1db;

mysql>

grant

allon user1db.*to

'user1'

@'localhost'

;

此時user1就擁有了對user1db資料庫的所有許可權。

如果我想限制user1只對資料庫有select許可權,而不讓他進行刪除和修改,那麼把上面的all替換成select就可。

之後可以通過show grants for 'user1'@'localhost';檢視授權資訊

revoke

select

,insert

,update

on user1db.

*from

'user1'

@'localhost'

;

現在來修改user1的登入密碼

mysql>

alter

user

'user1'@'localhost' identified by '

123456

'; #mysql8使用這種方式

mysql> set password for 'user1'@'localhost' = password('

123456')

;#mysql5.7使用這種方式

drop

user

'user1'

@'localhost'

;

mysql 管理位址 mysql8使用者管理

檢視當前登入使用者 建立使用者 create user 使用者名稱 主機位址 identified with mysql native password by 密碼 修改密碼 alter user 使用者名稱 主機位址 identified with mysql native password by...

mysql8建立不了使用者 mysql8建立使用者

假如是mysql8版本的話,使用 grant all privileges to 使用者 localhost identified by 自定義密碼 會報錯,因為要先建立使用者再進行賦權,不能同時進行 建立使用者 create user 使用者名稱 localhost identified by 密...

mysql8建立使用者

create user test user identified by test2022 grant allprivileges on test.to test user with grant option flush privileges 這樣就可以建立乙個叫 test user 的使用者並把密碼...