1。 改表法。
可能是你的帳號不允許從遠程登陸,只能在localhost。這個時候只要在localhost的那台電腦,登入mysql後,更改 "mysql" 數據庫裡的 "user" 表裡的 "host" 項,從"localhost"改成"%"
Sql代碼
1. mysql -u root -pvmwaremysql>use mysql;
2. mysql>update user set host = '%' where user = 'root';
3. mysql>select host, user from user;
例如,你想myuser使用mypassword從任何主機連接到mysql服務器的話。
Sql代碼
1. GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH
GRANT OPTION;
2.FLUSH PRIVILEGES;
如果你想允許用戶myuser從ip為192.168.1.6的主機連接到mysql服務器,並使用mypassword作為密碼
Sql代碼
1. GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY
2. 'mypassword' WITH GRANT OPTION;
3. FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY
'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
如果你想允許用戶myuser從ip為192.168.1.6的主機連接到mysql服務器的dk數據庫,並使用mypassword作為密碼
Sql代碼
1. GRANT ALL PRIVILEGES ON dk.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY
2. 'mypassword' WITH GRANT OPTION;
3. FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON dk.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY
'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
注意授權後必須FLUSH PRIVILEGES;否則無法立即生效。
另外一種方法.
在安裝mysql的機器上運行:
1、d:\mysql\bin\>mysql -h localhost -u root
//這樣應該可以進入MySQL服務器
2、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION
//賦予任何主機訪問數據的權限
3、mysql>FLUSH PRIVILEGES
//修改生效
4、mysql>EXIT
//退出MySQL服務器
這樣就可以在其它任何的主機上以root身份登錄啦!
其它:
mysql> grant all privileges on *.* to 'energy_pf'@'192.168.2.65' identified by 'energy_pf' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> plush privileges;
允許用戶energy_pf從ip為192.168.2.65的主機連接到mysql服務器的任意數據庫(*.*),並使用energy_pf作為密碼