1. 程式人生 > >如何給MySQL資料庫新增授權使用者

如何給MySQL資料庫新增授權使用者

1.首先登入MySQL資料庫

這個不用我多說了吧,不管你是Windows還是Ubuntu的系統,sql命令都是一樣的

mysql -u使用者名稱 -p
請輸入密碼:

使用者名稱的話,一般預設的為root

輸入你的密碼,進入你的資料庫是第一步,如果進不去,可以嘗試啟動你的MySQL資料庫的service,自行百度吧

2.新增可以訪問資料庫的使用者

授權格式:create user 使用者名稱 identified by '密碼';

 create user aiphare identified by '1314';

3.給指定使用者新增許可權

grant  許可權 on 資料庫.* to 使用者名稱;

1.新增可以通過外網IP進行查詢許可權的使用者

grant select on wechat.* to "aiphare"@"%" identified by "1314" with grant option;

2.新增可以本地訪問且擁有資料庫所有許可權的使用者

grant all privileges on wechat.* to [email protected] identified by '123456';

注意:其中localhost表示可以本地訪問,%表示可以遠端IP訪問,wechat是你要賦予的資料庫名,如果改為*表示全部的資料庫,不過考慮到安全,一般不這麼做.

4.重新整理許可權

flush privileges;

5.刪除使用者

drop user '使用者名稱'@'localhost或者%';

drop user 'aiphare'@'localhost';
drop user 'aiphare'@'%';

6.檢視使用者許可權

show grants for '使用者名稱'@'localhost或者%';

show grants for 'aiphare'@'%';

7.遠端連線資料庫

MySQL 連線遠端資料庫(192.168.131.131),埠“3306”,使用者名稱為“root”,密碼“123”;

mysql -h 192.168.131.131 -P 3306 -uaiphare -p1213;