编辑:我想从远程主机Mysql:
mysql -u root -p -h 192.168.56.147
但是我有这个消息:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.56.147' (111)
我已经在我的目标机器上完成了这个工作:
iptables -I INPUT -j ACCEPT
当我做一个netstat,我有这个:
root@opencv:/# netstat -ntlp | grep LISTEN tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1268/mysqld tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1249/sshd tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 1482/0 tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 1552/1 tcp6 0 0 :::22 :::* LISTEN 1249/sshd tcp6 0 0 ::1:6010 :::* LISTEN 1482/0 tcp6 0 0 ::1:6011 :::* LISTEN 1552/1
看来我的服务器只是在内部监听,而不是从外面听。
这是我的主机文件:
127.0.0.1 localhost 127.0.1.1 opencv # The following lines are desirable for IPv6 capable hosts #::1 localhost ip6-localhost ip6-loopback #ff02::1 ip6-allnodes #ff02::2 ip6-allrouters
这是我的hosts.allow:
# /etc/hosts.allow: list of hosts that are allowed to access the system. # See the manual pages hosts_access(5) and hosts_options(5). # # Example: ALL: LOCAL @some_netgroup # ALL: .foobar.edu EXCEPT terminalserver.foobar.edu # # If you're going to protect the portmapper use the name "rpcbind" for the # daemon name. See rpcbind(8) and rpc.mountd(8) for further information. # ALL: 192.168.0.0
而且telnet也不起作用:
root@DEBIANBASE:~# telnet 192.168.56.147 3306 Trying 192.168.56.147... telnet: Unable to connect to remote host: Connection refused
继亚历山大K的评论,这里是我的MySQLconfiguration的细节:
root@opencv:/# find . -name "my.cnf" ./var/lib/dpkg/alternatives/my.cnf ./etc/mysql/my.cnf ./etc/alternatives/my.cnf
但在每个文件中,没有“bind-address”选项或“skip-networking”选项(我在Ubuntu 16.10中)
挖掘之后,文件在这里:
nano /etc/mysql/mysql.conf.d/mysqld.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
然后我有这个:
root@DEBIANBASE:~# mysql -u root -p -h 192.168.56.147 Enter password: ERROR 1045 (28000): Access denied for user 'root'@'192.168.56.153' (using password: YES)
在我的本地MySQL服务器上添加远程用户之后:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.56.153' IDENTIFIED BY 'YOUR PASSWORD' WITH GRANT OPTION; FLUSH PRIVILEGES;
有效 ! 谢谢亚历山大。
文件/ etc / hosts和/etc/hosts.allow与IP绑定的MySQL无关。
正如你在这里看到的,它只绑定到127.0.0.1(回送)。
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1268/mysqld
你需要编辑你的/etc/my.cnf并像这样注释掉:
#skip-networking #bind-address = 127.0.0.1
这将使其绑定到所有可用的IP。
显然,如果你有多个IP(内部和外部),你可以select仅绑定到内部IP。
还要确保你有一个相应的root用户,允许你从连接的IP访问。