Case study of SQLyog client unable to connect to MySQL Server
-- View the Client ip Address [root @ mysql ~] # W 22:20:43 up, 1 user, load average: 0.00, 0.01, 0.05 user tty from login @ idle jcpu pcpu WHATroot pts/1 192.168.1.7 22:23:15 3.00 s 0.07 s 0.01 s w -- create client USER root @ localhost [(none)]> create user 'zlm '@' 192. 168.1.7 'identified by 'zlm '; Query OK, 0 rows affected (0.00 sec) -- use the newly created user to connect to the server through the SQLyog Client
The system prompts that the connection fails. "Can't connect to MySQL server" -- creates a local account root @ localhost 22:34:26 [(none)]> create user 'zlm '@' 192. 168.1.11 'identified by 'zlm '; Query OK, 0 rows affected (0.00 sec) root @ localhost 22:34:29 [(none)]> exitBye -- test whether [root @ mysql ~] can be connected # Mysql -- protocol = tcp-P 3306-h192.168.1.11-uzlm-pzlmWelcome to the MySQL monitor. commands end with; or \ g. your MySQL connection id is 19 Server version: 5.5.39-log MySQL Community Server (GPL) Copyright (c) 2000,201 4, Oracle and/or its affiliates. all rights reserved. oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. other names may be trademarks of their respectiv Eowners. type 'help; 'or' \ H' for help. type '\ C' to clear the current input statement. zlm@192.168.1.11 22:44:52 [(none)]> exitBye [root @ mysql ~] # Netstat-NKP | grep "3306" tcp 0 0.0.0.0: 3306 0.0.0.0: * LISTEN 3645/mysqld tcp 0 192.168.1.11: 3306 192.168.1.7: 59783 ESTABLISHED 3645/mysqld tcp 0 192.168.1.11: 3306 192.168.1.7: 59779 ESTABLISHED 3645/mysqld [root @ mysql ~] # Netstat-NCLP | grep "3306" | awk '{print $5}' | awk-F: '{print $1}' | sort | uniq-c | sort-nr 2 192.168.1.7
1 0.0.0.0 [root @ mysql ~] # Local users can use port 3306 to connect, indicating that the network is normal and port 3306 is enabled, in fact, the problem is that iptables uses chkconfig iptables off to close iptables of various terminals. It takes effect only after restart. At this time, it has not restarted [root @ mysql ~]. # Chkconfig iptables -- listiptables 0: off 1: off 2: on 3: on 4: on 5: on 6: off [root @ mysql ~] # Chkconfig iptables off [root @ mysql ~] # Chkconfig iptables -- listiptables 0: off 1: off 2: off 3: off 4: off 5: off 6: off -- disable iptables without restarting [root @ mysql ~] #/Etc/init. d/iptables stopiptables: Setting chains to policy ACCEPT: filter [OK] iptables: Flushing firewall rules: [OK] iptables: Unloading modules: [OK] [root @ mysql ~] #/Etc/init. d/iptables statusiptables: Firewall is not running. -- after iptables is disabled, the connection is established again.
If you do not want to disable iptables, add-a input-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT to/etc/sysconfig/iptables -- add allow rules to iptables (note not added at the end) [root @ mysql ~] # Vim/etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. * filter: input accept [0: 0]: forward accept [0: 0]: output accept [0: 0]-a input-m state -- state ESTABLISHED, RELATED-j ACCEPT-A INPUT-p icmp-j ACCEPT-A INPUT-I lo-j ACCEPT-A INPUT-m state -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT-A INPUT-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT -- allow port 3306 to pass through firewall-a input-j REJECT -- reject-with icmp-host-prohibited-a forward-j REJECT -- reject-with icmp-host- prohibitedCOMMIT -- restart iptables after modification [root @ mysql ~] #/Etc/init. d/iptables restartiptables: Setting chains to policy ACCEPT: filter [OK] iptables: Flushing firewall rules: [OK] iptables: Unloading modules: [OK] iptables: Applying firewall rules: [OK]
This time, I connected to the MySQL server through the SQLyog client. The connection is still successful! It can be seen that the problem of connection failure is that 3306 is blocked by the firewall.
Install MySQL and SQLyog in CentOS 6.3
Install MySQL in Ubuntu 14.04
MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF
Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL
Build a MySQL Master/Slave server in Ubuntu 14.04
Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS
Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04
MySQL-5.5.38 universal binary Installation
This article permanently updates the link address: