mysql 遠端連線資料庫的二種方法

2021-07-16 19:38:39 字數 2107 閱讀 1260

一、連線遠端資料庫:

1、顯示密碼

如:mysql 連線遠端資料庫(192.168.5.116),埠「3306」,使用者名為「root」,密碼「123456」

c:/>mysql -h 192.168.5.116 -p 3306 -u root -p123456

2、隱藏密碼

如:mysql 連線本地資料庫,使用者名為「root」,

c:/>mysql -h localhost -u root -p

enter password:

二、配置mysql允許遠端鏈結

預設情況下,mysql帳號不允許從遠端登陸,只能在localhost登入。本文提供了二種方法設定mysql可以通過遠端主機進行連線。

一、改表法

在localhost登入mysql後,更改 "mysql" 資料庫裡的 "user" 表裡的 "host" 項,將"localhost"改稱"%"

例如:#mysql -u root -p

enter password:

……mysql>

mysql>update user set host = '%' where user = 'root';

mysql>select host, user from user;

二、授權法

例如:你想myuser使用mypassword(密碼)從任何主機連線到mysql伺服器的話。

mysql>grant all privileges on *.* to 'myuser'@'%'identified by 'mypassword' with grant option;

如果你想允許使用者myuser從ip為192.168.1.6的主機連線到mysql伺服器,並使用mypassword作為密碼

mysql>grant all privileges on *.* to 'myuser'@'192.168.1.3'identified by

'mypassword' with grant option;

mysql>flush privileges

使修改生效,就可以了

常見問題:

1、在採用法二授權法之後,無法在本地登入mysql(如:#mysql -u root -p -h 192.168.5.116

enter password: 

error 1045 (28000): access denied for user 'root'@'loadb116' (using password: yes)

上例中loadb116是主機名.

解決方法:

1、這時可以使用:mysql  -u root -p 登入,進入到mysql後。

mysql>grant all privileges on *.* to 'root'@'loadb116' 

identified by '123456' with grant option;

query ok, 0 rows affected (0.00 sec)

mysql>flush privileges;

query ok, 0 rows affected (0.00 sec)

2、在本地使用ip位址登入

# mysql -u root -p -h 192.168.5.116

enter password: 

welcome to the mysql monitor.  commands end with ; or /g.

your mysql connection id is 60

server version: 5.1.45 mysql community server (gpl)

type 'help;' or '/h' for help. type '/c' to clear the buffer.

mysql>

mysql 遠端連線資料庫的二種方法

分類 資料mysql 2010 08 09 18 05 5475人閱讀收藏 舉報mysql 資料庫遠端連線 user server 伺服器 一 連線遠端資料庫 1 顯示密碼 如 mysql 連線遠端資料庫 192.168.5.116 埠 3306 使用者名為 root 密碼 123456 c mys...

mysql 遠端連線資料庫的二種方法

一 連線遠端資料庫 1 顯示密碼 如 mysql 連線遠端資料庫 192.168.5.116 埠 3306 使用者名為 root 密碼 123456 c mysql h 192.168.5.116 p 3306 u root p123456 2 隱藏密碼 如 mysql 連線本地資料庫,使用者名為 ...

mysql 遠端連線資料庫的二種方法

一 連線遠端資料庫 1 顯示密碼 如 mysql 連線遠端資料庫 192.168.5.116 埠 3306 使用者名為 root 密碼 123456 c mysql h 192.168.5.116 p 3306 u root p123456 2 隱藏密碼 如 mysql 連線本地資料庫,使用者名為 ...