預設情況下linux內的mysql資料庫mysql,user表內的使用者許可權只是對localhost即本機才能登陸。需要更改許可權:
如下的方式確認:
root#mysql -h localhost-u mysql -p
enter password: ******
welcome to the mysql monitor. commands end with ; or /g.
your mysql connection id is 4 to server version: 4.0.20a-debug
type 『help;』 or 『/h』 for help. type 『/c』 to clear the buffer.
mysql> use mysql; (此db存放mysql的各種配置資訊)
database changed
mysql> select host,user from user; (檢視使用者的許可權情況)
+————-+——-+
| host | user |
+————-+——-+
| localhost | |
| localhost | root |
| localhost | |
| localhost | mysql |
+————-+——-+
6 rows in set (0.02 sec)
由此可以看出,只能以localhost的主機方式訪問。
解決方法:
mysql> grant all privileges on *.* to 『root』@'%』 identified by 『password』with grant option;
(%表示是所有的外部機器,如果指定某一台機,就將%改為相應的機器名;『root』則是指要使用的使用者名稱,)
mysql> flush privileges; (執行為句才生效,或者重啟mysql)
query ok, 0 rows affected (0.03 sec)
mysql> select host,user from user; (再次檢視使用者的許可權情況)
+————-+——-+
| host | user |
+————-+——-+
| % | mysql |
| % | root |
| localhost | |
| localhost | root |
| localhost | |
| localhost | mysql |
+————-+——-+
mysql>exit
現在再試試:
root#mysql -h mysql -u root -p
enter password:******
welcome to the mysql monitor. commands end with ; or /g.
your mysql connection id is 9 to server version: 4.0.20a-debug
type 『help;』 or 『/h』 for help. type 『/c』 to clear the buffer.
mysql>
就成功連線上了。
如果使用以上方法仍然不能遠端連線mysql,那可能是如下原因導致的問題
1、linux的防火牆開了,遮蔽了mysql的3306埠,導致mysql連線不上
2、phpmyadmin裡root使用者下的「許可權」標籤下有個「按資料庫指定許可權」選項。需要「在下列資料庫新增許可權:」下拉選定你要設定的資料庫及他的許可權。這樣才可以連線那個資料庫。
mysql遠端連線設定 MySQL遠端連線設定
這只是乙個簡單mysql設定。但很多圖簡單,卻忽略了安全性。所以對設定中的細節和含義需要弄到清清楚楚才行。這只是乙個簡單mysql設定。但很多圖簡單,卻忽略了安全性。所以對設定中的細節和含義需要弄到清清楚楚才行。mysql遠端連線的設定問題 下面是步驟 1 登陸本地的mysql server mys...
mysql 設定遠端連線
授權法 grant select,insert,update,delete,create,drop on tablename.to username localhost identified by password 注意 tablename 你自己資料庫的名字,username 連線庫使用者名稱,l...
mysql設定遠端連線
1,開啟mysql遠端連線 1,獲取root許可權 sudo i 2,cd到配置檔案所在路徑 cd etc mysql mysql.conf.d 3,vi mysqld.cnf bind address 127.0.0.1 瀏覽模式 a 插入模式 esc 瀏覽模式 shift 命令列模式 wq 儲存...