mysql_使用客户端工具和命令来创建用户和分配权限方法
涓銆佺敤鎴锋潈闄愶紙浣跨敤Navicat鍒涘缓鐢ㄦ埛鍜屽垎閰嶆潈闄愶級
1銆佹潈闄愮粨鏋勶細鍏ㄥ眬/鏁版嵁搴/琛/鍒楁潈闄
2銆佷富瑕佹潈闄愶紙鍏ㄩ儴鏉冮檺-ALL锛夛細
3銆佹潈闄愬垎甯冿細
浜屻佷娇鐢∟avicat瀹㈡埛绔伐鍏峰垱寤虹敤鎴峰拰鍒嗛厤鏉冮檺锛
(1) 鍏ㄥ眬鏉冮檺锛
(2) 鏁版嵁搴撴潈闄愶細
3) 琛ㄦ潈闄愶細
(4)鍒楁潈闄愶細
涓夈乵ysql鍒嗛厤鏉冮檺鐩稿叧鍛戒护锛堟巿鏉僩rant銆佹煡鐪嬫潈鍒﹕how grants銆佹挙閿鏉冨埄revok銆佸垹闄ょ敤鎴穌rop user锛夛細
1銆佽祴浜堟潈闄愬懡浠 grant锛
鈻 璇硶锛
grant 鏉冮檺
on 鏁版嵁搴撳璞
to 鐢ㄦ埛 identified by 鈥樺瘑鐮佲
with grant option;
(1) 褰撳凡缁忓瓨鍦ㄧ敤鎴凤紙渚嬪shan锛夋椂锛岃祴浜堟煡璇㈡潈闄愬湪鏁版嵁搴搈ysqldemo涓殑琛╰_stu(鏁版嵁搴撳璞)鍒扮敤鎴穝han
璇硶锛歡rant select on mysqldemo.t_stu to shan@localhost;
grant 鏉冮檺
on 鏁版嵁搴撳璞
to 鐢ㄦ埛;
(2) 褰撶敤鎴蜂笉瀛樺湪鏃讹紙渚:鍒涘缓鐢ㄦ埛shan锛屽瘑鐮佹槸1锛夛紝璧嬩簣鏌ヨ鏉冮檺鍦ㄦ暟鎹簱mysqldemo涓殑琛╰_stu(鏁版嵁搴撳璞) 鍒扮敤鎴穝han
璇硶: grant select on mysqldemo.t_stu to shan@localhost identified by 鈥1鈥;
grant 鏉冮檺
on 鏁版嵁搴撳璞
to 鐢ㄦ埛 identified by 鈥樺瘑鐮佲;
(3) 褰撶敤鎴蜂笉瀛樺湪鏃, 灏嗘巿鏉僄RANT OPTION 鐨勬潈鍒╀篃璧嬬粰褰撳墠鐢ㄦ埛锛堜緥:鍒涘缓鐢ㄦ埛shan锛屽瘑鐮佹槸1锛夛紝璧嬩簣鏌ヨ鏉冮檺鍦ㄦ暟鎹簱mysqldemo涓殑琛╰_stu(鏁版嵁搴撳璞) 鍒扮敤鎴穝han
璇硶: grant select on mysqldemo.t_stu to shan@localhost identified by 鈥1鈥 with grant option;
grant 鏉冮檺
on 鏁版嵁搴撳璞
to 鐢ㄦ埛 identified by 鈥樺瘑鐮佲
with grant option;
鉁 鍒嗛厤鏉冮檺鐨勭粏鑺傦細
鈻 shan@localhost锛歴han鐢ㄦ埛锛屾槸鍙兘鍦ㄦ湰鍦颁富鏈鸿闂
鈻 鐢ㄦ埛璐﹀彿锛歶ser@host锛屽叾涓環ost鐨勫硷紝% 浠庝换鎰忓湴鍧璁块棶锛 10.250.8.% 鍙兘璁块棶鐗瑰畾鐨勭綉娈碉紝 192.168.1.8 鍙兘璁块棶鐗瑰畾鐨刬p銆
localhost: 鏈満鍦板潃銆
鈻 鏌ョ湅鐢佃剳ip鍛戒护锛歩pconfig
2銆佹煡鐪嬬敤鎴风殑鏉冮檺鍛戒护 show grants锛
(1) 鏌ョ湅褰撳墠鐢ㄦ埛鏉冮檺锛 show grants;
(2) 鏌ョ湅鏌愪釜鐢ㄦ埛鏉冮檺锛 show grants for 鐢ㄦ埛璐﹀彿锛
鈥 渚嬪锛氬湪cmd鎺у埗鍙帮紝浠oot 鐢ㄦ埛杩涘叆mysql锛岀劧鍚庢煡鐪媗ucy鐨勬潈闄愶細 show grants for lucy@localhost;
3銆佸洖鏀舵潈闄愬懡浠 revoke锛
鈻 璇硶锛
revoke 鏉冮檺
on 鏁版嵁搴撳璞
from 鐢ㄦ埛锛
渚嬪锛歳evoke select on . from lucy@localhost;
鈻 娉ㄦ剰锛氫娇鐢╮evoke 鍥炴敹鎵鏈夋潈闄愶紝鍒欐搷浣滆呭繀椤绘槸鎷ユ湁mysql鏁版嵁鐨勫叏灞create user鎴 update 鏉冮檺銆
4銆佸垹闄ょ敤鎴疯处鍙锋潈闄 drop user锛
鈻 璇硶锛歞rop user 鐢ㄦ埛璐﹀彿锛
渚嬪锛歞rop user lucy@localhost;
鑻ヤ富鏈烘槸%锛岃娉曡寰楀姞涓 鈥樷 渚嬪锛歞rop user lucy@鈥%鈥;
1銆佹潈闄愮粨鏋勶細鍏ㄥ眬/鏁版嵁搴/琛/鍒楁潈闄
2銆佷富瑕佹潈闄愶紙鍏ㄩ儴鏉冮檺-ALL锛夛細
3銆佹潈闄愬垎甯冿細
浜屻佷娇鐢∟avicat瀹㈡埛绔伐鍏峰垱寤虹敤鎴峰拰鍒嗛厤鏉冮檺锛
(1) 鍏ㄥ眬鏉冮檺锛
(2) 鏁版嵁搴撴潈闄愶細
3) 琛ㄦ潈闄愶細
(4)鍒楁潈闄愶細
涓夈乵ysql鍒嗛厤鏉冮檺鐩稿叧鍛戒护锛堟巿鏉僩rant銆佹煡鐪嬫潈鍒﹕how grants銆佹挙閿鏉冨埄revok銆佸垹闄ょ敤鎴穌rop user锛夛細
1銆佽祴浜堟潈闄愬懡浠 grant锛
鈻 璇硶锛
grant 鏉冮檺
on 鏁版嵁搴撳璞
to 鐢ㄦ埛 identified by 鈥樺瘑鐮佲
with grant option;
(1) 褰撳凡缁忓瓨鍦ㄧ敤鎴凤紙渚嬪shan锛夋椂锛岃祴浜堟煡璇㈡潈闄愬湪鏁版嵁搴搈ysqldemo涓殑琛╰_stu(鏁版嵁搴撳璞)鍒扮敤鎴穝han
璇硶锛歡rant select on mysqldemo.t_stu to shan@localhost;
grant 鏉冮檺
on 鏁版嵁搴撳璞
to 鐢ㄦ埛;
(2) 褰撶敤鎴蜂笉瀛樺湪鏃讹紙渚:鍒涘缓鐢ㄦ埛shan锛屽瘑鐮佹槸1锛夛紝璧嬩簣鏌ヨ鏉冮檺鍦ㄦ暟鎹簱mysqldemo涓殑琛╰_stu(鏁版嵁搴撳璞) 鍒扮敤鎴穝han
璇硶: grant select on mysqldemo.t_stu to shan@localhost identified by 鈥1鈥;
grant 鏉冮檺
on 鏁版嵁搴撳璞
to 鐢ㄦ埛 identified by 鈥樺瘑鐮佲;
(3) 褰撶敤鎴蜂笉瀛樺湪鏃, 灏嗘巿鏉僄RANT OPTION 鐨勬潈鍒╀篃璧嬬粰褰撳墠鐢ㄦ埛锛堜緥:鍒涘缓鐢ㄦ埛shan锛屽瘑鐮佹槸1锛夛紝璧嬩簣鏌ヨ鏉冮檺鍦ㄦ暟鎹簱mysqldemo涓殑琛╰_stu(鏁版嵁搴撳璞) 鍒扮敤鎴穝han
璇硶: grant select on mysqldemo.t_stu to shan@localhost identified by 鈥1鈥 with grant option;
grant 鏉冮檺
on 鏁版嵁搴撳璞
to 鐢ㄦ埛 identified by 鈥樺瘑鐮佲
with grant option;
鉁 鍒嗛厤鏉冮檺鐨勭粏鑺傦細
鈻 shan@localhost锛歴han鐢ㄦ埛锛屾槸鍙兘鍦ㄦ湰鍦颁富鏈鸿闂
鈻 鐢ㄦ埛璐﹀彿锛歶ser@host锛屽叾涓環ost鐨勫硷紝% 浠庝换鎰忓湴鍧璁块棶锛 10.250.8.% 鍙兘璁块棶鐗瑰畾鐨勭綉娈碉紝 192.168.1.8 鍙兘璁块棶鐗瑰畾鐨刬p銆
localhost: 鏈満鍦板潃銆
鈻 鏌ョ湅鐢佃剳ip鍛戒护锛歩pconfig
2銆佹煡鐪嬬敤鎴风殑鏉冮檺鍛戒护 show grants锛
(1) 鏌ョ湅褰撳墠鐢ㄦ埛鏉冮檺锛 show grants;
(2) 鏌ョ湅鏌愪釜鐢ㄦ埛鏉冮檺锛 show grants for 鐢ㄦ埛璐﹀彿锛
鈥 渚嬪锛氬湪cmd鎺у埗鍙帮紝浠oot 鐢ㄦ埛杩涘叆mysql锛岀劧鍚庢煡鐪媗ucy鐨勬潈闄愶細 show grants for lucy@localhost;
3銆佸洖鏀舵潈闄愬懡浠 revoke锛
鈻 璇硶锛
revoke 鏉冮檺
on 鏁版嵁搴撳璞
from 鐢ㄦ埛锛
渚嬪锛歳evoke select on . from lucy@localhost;
鈻 娉ㄦ剰锛氫娇鐢╮evoke 鍥炴敹鎵鏈夋潈闄愶紝鍒欐搷浣滆呭繀椤绘槸鎷ユ湁mysql鏁版嵁鐨勫叏灞create user鎴 update 鏉冮檺銆
4銆佸垹闄ょ敤鎴疯处鍙锋潈闄 drop user锛
鈻 璇硶锛歞rop user 鐢ㄦ埛璐﹀彿锛
渚嬪锛歞rop user lucy@localhost;
鑻ヤ富鏈烘槸%锛岃娉曡寰楀姞涓 鈥樷 渚嬪锛歞rop user lucy@鈥%鈥;