mysql收回許可權 MySQL學習之路(九)

2021-10-17 10:40:57 字數 2276 閱讀 5102

1.備份

mysqldump -u使用者名稱 -h賬號 --default-character-set=編碼方式 -p 資料庫名》位置/備份檔案名.sql

2.登陸資料庫

mysql -h 賬號-u 使用者名稱 -p

3.備份的是資料庫資料,所以必須先刪除原本的資料庫

然後建立乙個同名資料庫

4.恢復資料庫

mysql -uroot -p 資料庫名《路徑/備份的sql名

5.恢復成功

使用者的資料在名為mysql資料庫裡面

後面加上with grant option,就可以在這個新建立的使用者下建立新的使用者並賦予許可權

1.增加使用者

方法一:

使用create user語句建立使用者

該語句建立的使用者是沒有許可權的

建立乙個名稱為zdp密碼為123且只能在本地登陸的使用者

localhost指的是只能在本地登陸

如果為%即可以在遠端登陸

(棄用)方法二:

可以對使用者進行授權,不需要手動重新整理

使用grant語句建立乙個新使用者,使用者名為hnzj,密碼為123.並且授予 使用者名稱對「學生選課.teacher」表有查詢(select)許可權

all privileges 所有許可權

'資料庫民'.* 資料庫的所有表

方法三:

insert語句建立使用者

注意這個語句沒有重新整理許可權表的功能,因此建立的使用者暫時不能使用,應該手動重新整理或重新啟動mysql服務

重新整理許可權表語句如下

flush privileges;

2.刪除使用者

方法一:

drop user 『使用者名稱』@『localhost/%』;

栗子:用root使用者登入資料庫伺服器,使用drop user語句刪除使用者

方法二:

delete from mysql.user where host='localhost/%' and user='使用者名稱';

3.修改

修改使用者名稱:

rename user '使用者名稱'@'localhost/%' to '新使用者名稱'@'localhost/%';

修改使用者名稱密碼:

方法一:

修改root使用者的密碼

mysqladmin -u root -p password 新密碼;

(棄用)方法二:

使用update修改root密碼

update mysql.user set password'新密碼' where user='root' and host='localhost';

(棄用了)方法三:

登入root後使用下列語句修改root密碼

set password=password('新密碼')

1.檢視許可權

show grants for '使用者名稱'@'localhost/%/某個主機名ip'

2.收回許可權

revoke 許可權(select,insert,all privileges,grant option,...) (on *.*) from '許可權名'@'localhost';

賦予 收回 查詢許可權

grant privileges columns on database.table to username hostname identified by password password username hostname identified by password password with...

mysql 重新整理許可權 mysql許可權

1,檢視所有使用者許可權 select distinct concat user user,host,as query from mysql.user 或者 select from mysql.user 2,檢視某乙個使用者的許可權 show grants for user ip 3,分配許可權 以...

SQL許可權授予和收回

grant select 把查詢student表的許可權授給使用者ui on table student to ui grant select on table student to public with grant option revoke select 收回許可權 on table sc f...