MySQL授權管理

2021-10-12 17:31:26 字數 2415 閱讀 3242

總結安裝mysql後,給資料庫分配使用者和授權。

mysql> use mysql;

mysql> desc user;

mysql> grant all privileges on *.* to root@"%" identified by "root"

; //為root新增遠端連線的能力

mysql> update user set password = password(

'123456'

) where user=

'root'

; //設定root使用者密碼

mysql>

select host,user,password from user where user=

'root'

; mysql> flush privileges;

mysql>

exit

(1)檢視mysql的所有使用者及其許可權:

select * from mysql.user\g;
(2)檢視當前mysql使用者許可權:

show grants;
(3)檢視某個使用者的許可權:

show grants for username@host;

#使用者名稱@主機

show grants for test@localhost;

(4)檢視所有使用者

select host,user from mysql.user;
(1)mysql使用者建立:

create user '使用者名稱'@'主機' identified by '密碼'

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

;flush privileges;

#建立完使用者及許可權後,需要使用該命令重新整理許可權

(2) mysql使用者刪除:

drop user '使用者名稱'@'主機'

;

(3) mysql使用者許可權授予:

grant 許可權列表 on 資料庫名.資料表名 to 『使用者名稱』@』主機』 identified by 『密碼』 with grant option;

#資料庫名.*代表庫下所有的表

grant all privileges on *.* to 'test'@'%' identified by 'test098' with grant option;

flush privileges;

可使用「*」表示所有資料庫或所有資料表,「%」表示任何主機位址。

(4)mysql使用者許可權**:

revoke 許可權列表 on 資料庫名.資料表名 from 使用者名稱@主機;

revoke drop on *.* from test@localhost;

#**drop許可權

(5)對賬戶重新命名:

rename user '舊使用者名稱'@'舊主機' to '新使用者名稱'@'新主機'

;rename user 'test'@'localhost' to 'test1'@'localhost'

;

(6)mysql使用者密碼修改:

使用set password命令

set password for

'使用者名稱'@'主機'

= password(

'新密碼');

#需要執行重新整理許可權

flush privileges;

set password for

'test'@'localhost'

= password(

'123456');

flush privileges;

使用set password命令

grant select on 資料庫名.資料表名 to 使用者名稱@主機 identified by '新密碼' with grant option;

grant select on test.user to test@localhost identified by '111111' with grant option;

執行mysqladmin指令碼檔案。

(1)使用者尚無密碼:

mysqladmin -u 使用者名稱 password 新密碼;

(2)使用者已有密碼:

mysqladmin -u 使用者名稱 -p password 新密碼;

許可權操作後要重新整理 才生效

mysql 授權管理

本文從建立乙個資料庫說起 1,建立乙個資料庫 create database if not exists you dbname default charset utf8 callate utf8 general ci 2,訪問控制介紹 mysql 伺服器的安全基礎是 使用者應該對他們需要的資料具有適...

MySQL管理使用者,授權

管理使用者 create user 使用者名稱 主機名 identified by 密碼 drop user 使用者名稱 主機名 update user set password password 新密碼 where user 使用者名稱 set password for 使用者名稱 主機名 pas...

mysql授權 使用者管理 MySQL使用者管理 授權

建立使用者 命令 create user username host identified by password 說明 username 建立的使用者名稱 host 使用者可以在哪個主機上登入,任意主機選擇 password 使用者的密碼 例 create user arvin identifie...