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; java
2. 受權法。例如,你想myuser使用mypassword從任何主機鏈接到mysql服務器的話。
Sql代碼 複製代碼 mysql
1. GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH 程序員
GRANT OPTION;
2.FLUSH PRIVILEGES; sql
若是你想容許用戶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的機器上運行:
一、d:\mysql\bin\>mysql -h localhost -u root
//這樣應該能夠進入MySQL服務器
二、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION
//賦予任何主機訪問數據的權限
三、mysql>FLUSH PRIVILEGES
//修改生效
四、mysql>EXIT
//退出MySQL服務器
這樣就能夠在其它任何的主機上以root身份登陸啦! 數據庫