方法1、本地登入mysql,更改 "mysql" 數據庫裏的 "user" 表裏的 "host" 項,將"localhost"改成"%" #mysql -u root -p mysql>use mysql; mysql>update user set host = '%' where user = 'root'; mysql>select host, user from user;mysql
方法2、直接受權(推薦) 從任何主機上使用root用戶,密碼:youpassword(你的root密碼)鏈接到mysql服務器: mysql>GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION; 容許地址202.11.10.253上用root用戶,密碼dboomysql來鏈接mysql的全部數據庫,付給select,insert,update,delete權限。 grant select,insert,update,delete on . to root@"202.11.10.253" Identified by "dboomysql"; 容許地址202.11.10.253上用root用戶,密碼dboomysql來鏈接mysql的全部數據庫,付給全部權限。 grant all on . to root@"202.11.10.253" Identified by "dboomysql"sql
操做完後切記執行如下命令刷新權限 FLUSH PRIVILEGES數據庫
2.2 首先爲用戶建立一個數據庫(testDB): //建立用戶 insert into mysql.user(Host,User,Password) values("localhost","test",password("1234")); 這樣就建立了一個名爲:test 密碼爲:1234 的用戶。 注意:此處的"localhost",是指該用戶只能在本地登陸,不能在另一臺機器上遠程登陸。若是想遠程登陸的話,將"localhost"改成"%",表示在任何一臺電腦上均可以登陸。也能夠指定某臺機器能夠遠程登陸。服務器
mysql>create database testDB;ide
2.3 受權test用戶擁有testDB數據庫的全部權限(某個數據庫的全部權限):.net
mysql>grant all privileges on testDB.* to test@localhost identified by '1234';code
mysql>flush privileges;//刷新系統權限表get
格式:grant 權限 on 數據庫.* to 用戶名@登陸主機 identified by "密碼"; table
2.4 若是想指定部分權限給一用戶,能夠這樣來寫:test
mysql>grant select,update on testDB.* to test@localhost identified by '1234';
mysql>flush privileges; //刷新系統權限表
2.5 受權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';便可。