問題一:本機(localhost)串連一切正常,但是無法從其他電腦上登入 MySQL 資料庫!
下面是 /etc/mysql/my.cnf 中的一段摘錄:
# Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 10.0.0.1 # 127.0.0.1
|
其中說明 MySQL預設設定為只在 localhost 進行偵聽,所以如果登入的 MySQL Client 與 MySQL Server 不為同一台電腦的話,MySQL 是不會響應的。故需要把這裡的 bind-address 修改為此台電腦的 external IP 即可。
問題二:ERROR 1045 (28000): Access denied for user 'root'@'10.0.0.1' (using password: YES) !
這個也是頗有意思,首先看看原本系統資料表中的資料:
mysql> USE mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Database changed
mysql> SELECT Host FROM user WHERE user='root'; +-----------+ | Host | +-----------+ | sharkwang | | localhost | +-----------+ 2 rows in set (0.00 sec)
|
恩,這裡除了有 localhost 外,居然還有一個 sharkwang ,而我串連的時候是用IP而不是hostname !
所以,有2個方案:
1. 在 MySQL Client 所在的電腦上面,修改 /etc/hosts 檔案,加入 hostname 和 IP 的映射關係。
登入方式為: shell> mysql -h <mysql_server_hostname> -u root -p
2. 在 MySQL 資料庫的 user 表中增加一條記錄,內容參照:
SELECT * FROM user WHERE User='root' AND Host='localhost'
然後把 Host 對應的值修改為 MySQL Server 的 external IP。
登入方式為: shell> mysql -h <mysql_server_ip> -u root -p