一、連線遠端資料庫:
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命令 一 連線資料庫
1 mysql命令連線資料庫格式 mysql h 主機位址 p 埠號 u使用者名稱 p使用者密碼2 mysql連線本地資料庫,使用者名為 root 密碼 123 mysql h localhost u root p123注意 1 使用者名稱前可以有空格也可以沒有空格,但是密碼前必須沒有空格,否則讓你...
MySQL的儲存(一 連線資料庫)
確保安裝mysql 安裝pymysql庫 這裡首先嘗試連線下資料庫,假設當前mysql執行在本地,使用者名為root,密碼為123456,執行埠為3306。通過pymysql的connect 方法宣告乙個mysql連線物件db,傳入mysql執行的host。由於mysql是在本地執行,所以傳入loc...
php學習記錄一 連線資料庫
header content type text html charset utf 8 header access control allow origin header access control allow methods get,post,options,delete header acce...