00x1建立新用戶html
經過root用戶登陸以後建立mysql
建立新用戶,用戶名爲testuser,密碼爲123456 ;sql
grant all privileges on *.* to testuser@localhost identified by "123456" ;
設置用戶testuser,能夠在本地訪問mysql數據庫
grant all privileges on *.* to testuser@localhost identified by "123456" ;
設置用戶testuser,能夠在遠程訪問mysql 服務器
grant all privileges on *.* to testuser@"%" identified by "123456" ;
mysql 新設置用戶或更改密碼後需用flush privileges刷新MySQL的系統權限相關表,不然會出現拒絕訪問,還有一種方法,就是從新啓動mysql服務器,來使新設置生效ide
flush privileges ;
00x2設置用戶訪問數據庫權限spa
設置用戶testuser,只能訪問數據庫test_db,其餘數據庫均不能訪問 ;code
grant all privileges on test_db.* to testuser@localhost identified by "123456" ;
設置用戶testuser,能夠訪問mysql上的全部數據庫 ;htm
grant all privileges on *.* to testuser@localhost identified by "123456" ;
設置用戶testuser,只能訪問數據庫test_db的表user_infor,數據庫中的其餘表均不能訪問 ;blog
grant all privileges on test_db.user_infor to testuser@localhost identified by "123456" ;
00x3設置用戶操做權限
設置用戶testuser,擁有全部的操做權限,也就是管理員 ;
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
00x4設置用戶遠程訪問權限
設置用戶testuser,只能在客戶端IP爲192.168.1.100上才能遠程訪問mysql ;
grant all privileges on *.* to testuser@「192.168.1.100」 identified by "123456" ;
00x5關於root用戶的訪問設置
設置全部用戶能夠遠程訪問mysql,修改my.cnf配置文件,將bind-address = 127.0.0.1前面加「#」註釋掉,這樣就能夠容許其餘機器遠程訪問本機mysql了;
設置用戶root,能夠在遠程訪問mysql
grant all privileges on *.* to root@"%" identified by "123456" ;
查詢mysql中全部用戶權限
select host,user from user;
關閉root用戶遠程訪問權限
禁止root用戶在遠程機器上訪問mysql
delete from user where user="root" and host="%" ;
修改權限以後,刷新MySQL的系統權限相關表方可生效
flush privileges ;
轉載於:http://www.cnblogs.com/candle806/p/4048651.html