Mysql創建、刪除用戶

基礎mysql用戶操作

創建用戶:

mysql> insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));

  這樣就創建了一個名爲:test 密碼爲:1234 的用戶。

  注意:此處的"localhost",是指該用戶只能在本地登錄,不能在另外一臺機器上遠程登錄。如果想遠程登錄的話,將"localhost"改爲"%",表示在任何一臺電腦上都可以登錄。也可以指定某臺機器可以遠程登錄。

 

授權用戶:

 

  授權格式:grant 權限 on 數據庫.* to 用戶名@登錄主機 identified by "密碼"; 

  • 授權test用戶擁有testDB數據庫的所有權限(某個數據庫的所有權限):

   mysql>grant all privileges on testDB.* to test@localhost identified by '1234';

   mysql>flush privileges;//刷新系統權限表

  格式:grant 權限 on 數據庫.* to 用戶名@登錄主機 identified by "密碼"; 

  • 如果想指定部分權限給一用戶,可以這樣來寫:

  mysql>grant select,update on testDB.* to test@localhost identified by '1234';

  mysql>flush privileges; //刷新系統權限表

  • 授權test用戶擁有所有數據庫的某些權限   

  mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";

     //test用戶對所有數據庫都有select,delete,update,create,drop 權限。

  //@"%" 表示對所有非本地主機授權,不包括localhost。(localhost地址設爲127.0.0.1,如果設爲真實的本地地址,不知道是否可以,沒有驗證。)

//對localhost授權:加上一句grant all privileges on testDB.* to test@localhost identified by '1234';即可。

刪除用戶

 mysql>Delete FROM user Where User='test' and Host='localhost';

 mysql>flush privileges;

 mysql>drop database testDB; //刪除用戶的數據庫

刪除賬戶及權限:>drop user 用戶名@'%';

        >drop user 用戶名@ localhost; 

修改指定用戶密碼

  mysql>update mysql.user set password=password('新密碼') where User="test" and Host="localhost";

  mysql>flush privileges;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章