Ubuntu上的MySQL可以遠程訪問
阿新 • • 發佈:2017-08-22
1.2 etc 重新 color oot which 成功 netstat tle
1. 3306端口是不是沒有打開?
使用nestat命令查看3306端口狀態:
~# netstat -an | grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
從結果可以看出3306端口只是在IP 127.0.0.1上監聽,所以拒絕了其他IP的訪問。
解決方法:修改/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 = 127.0.0.1
把上面這一行註釋掉或者把127.0.0.1換成合適的IP,建議註釋掉。
重新啟動後,重新使用netstat檢測:
~# netstat -an | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
2. 問題解決了嗎?
現在使用下面命令測試:
~# mysql -h 10.1.1.2 -u root -p Enter password: ERROR 1130 (00000): Host ‘B0324-Desktop.local‘ is not allowed to connect to this MySQL server
結果出乎意料,還是不行。
解決方法:原來還需要把用戶權限分配各遠程用戶。
登錄到mysql服務器,使用grant命令分配權限
mysql> grant all on database_name.* to [email protected]%‘ identified by ‘user_password‘;
其中database_name、user_name和user_password根據實際情況設置。
完成後使用mysql命令連接,提示成功,為了確保正確可以再遠程登陸測試一下。
轉自:http://blog.csdn.net/mydeman/article/details/3847695
Ubuntu上的MySQL可以遠程訪問