linux下mysql遠程訪問
Mysql默認root用戶只能本地訪問,不能遠程連接管理mysql數據庫,但項目中必須要遠程導 入導出數據,所以研究了一下。
Table of Contents
1 修改localhost
- 更改 "mysql" 數據庫里的 "user" 表里的 "host" 項,從"localhost"改成"%"
mysql>use mysql; mysql>update user set host ="%" where user = "root"; mysql>select host, user from user; mysql>FLUSH PRIVILEGES;
- 這時的user表應該是這樣的
mysql> select * from user; +-----------+------------------+- | Host | User | +-----------+------------------+- | % | root | | debian | root | | 127.0.0.1 | root | | ::1 | root | | % | | | debian | | | % | debian-sys-maint | +-----------+------------------+- 7 rows in set (0.00 sec)
2 配置/etc/mysql/my.cnf
查看/etc/mysql/my.cnf中,skip-networking 是否已被注掉 sudo gedit /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 # 改為: # # 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 #
3 其他
1 Mysql的端口是否正確
通過netstat -ntlp查看端口占用情況,一般情況下端口是3306。在用工具連接MySQl是要用 到端口。例如My Admin\My Query Browser\MySQl Front等。
2 查看iptables是否停掉,沒關的情況下,無法連接
通過:service iptables stop臨時關閉 報錯:ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.51.112' (113)