天天看點

linux下Mysql指令

1,進入mysql,終端中輸入 mysql -u 使用者名 -p   。enter鍵後,提示輸入密碼。

2,執行grant all privileges on xxxdb.* to usertest@"%" identified by "passdtest"; 增加使用者usertest,密碼為passdtest。其對資料庫xxxdb有所有權限。可以外網通路。

3,show databases;  顯示此使用者下的資料庫

4,select host,user from mysql.user;  檢視使用者的權限

1、建立新使用者

  通過root使用者登入之後建立

  >> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  建立新使用者,使用者名為testuser,密碼為123456 ;

  >> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  設定使用者testuser,可以在本地通路mysql

  >> grant all privileges on *.* to testuser@"%" identified by "123456" ;   //  設定使用者testuser,可以在遠端通路mysql

  >> flush privileges ;  //  mysql 新設定使用者或更改密碼後需用flush privileges重新整理MySQL的系統權限相關表,否則會出現拒絕通路,還有一種方法,就是重新啟動mysql伺服器,來使新設定生效

  

  2、設定使用者通路資料庫權限

  >> grant all privileges on test_db.* to testuser@localhost identified by "123456" ;  //  設定使用者testuser,隻能通路資料庫test_db,其他資料庫均不能通路 ;

  >> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  設定使用者testuser,可以通路mysql上的所有資料庫 ;

  >> grant all privileges on test_db.user_infor to testuser@localhost identified by "123456" ;  //  設定使用者testuser,隻能通路資料庫test_db的表user_infor,資料庫中的其他表均不能通路 ;

  3、設定使用者操作權限

  >> grant all privileges on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION ;  //設定使用者testuser,擁有所有的操作權限,也就是管理者 ;

  >> grant select on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION ;  //設定使用者testuser,隻擁有【查詢】操作權限 ;

  >> grant select,insert on *.* to testuser@localhost identified by "123456"  ;  //設定使用者testuser,隻擁有【查詢\插入】操作權限 ;

  >> grant select,insert,update,delete on *.* to testuser@localhost identified by "123456"  ;  //設定使用者testuser,隻擁有【查詢\插入】操作權限 ;

  >> REVOKE select,insert ON what FROM testuser  //取消使用者testuser的【查詢\插入】操作權限 ;

  4、設定使用者遠端通路權限

  >> grant all privileges on *.* to testuser@“192.168.1.100” identified by "123456" ;  //設定使用者testuser,隻能在用戶端IP為192.168.1.100上才能遠端通路mysql ;

  5、關于root使用者的通路設定

  設定所有使用者可以遠端通路mysql,修改my.cnf配置檔案,将bind-address = 127.0.0.1前面加“#”注釋掉,這樣就可以允許其他機器遠端通路本機mysql了;

  >> grant all privileges on *.* to root@"%" identified by "123456" ;   //  設定使用者root,可以在遠端通路mysql

  >> select host,user from user;   //查詢mysql中所有使用者權限

  關閉root使用者遠端通路權限

  >> delete from user where user="root" and host="%" ;  //禁止root使用者在遠端機器上通路mysql

  >> flush privileges ;  //修改權限之後,重新整理MySQL的系統權限相關表方可生效  

QQ:519841366

本頁版權歸作者和部落格園所有,歡迎轉載,但未經作者同意必須保留此段聲明,

且在文章頁面明顯位置給出原文連結,否則保留追究法律責任的權利