There are three situations in which port 3306 cannot be connected.

1. Port 3306 is not enabled on the firewall on the local machine. You need to configure inbound rules or disable the firewall on the local machine.

2. The Iptables firewall on the Linux server does not enable port 3306 or disable the firewall on the server.

Open the

/etc/sysconfig/iptables
Copy the code

in

"-A INPUT -- m state --state NEW -- m TCP -- p -- dport 22 -- j ACCEPT"Copy the code

, next add:


 -A INPUT -m state --state NEW -m tcp -p -dport 3306 -j ACCEPT
Copy the code

3. No remote permission is granted to mysql users

    

mysql> USE mysql;
Copy the code

Switch to mysql DB

Database changed
Copy the code
mysql> SELECT User, Password, Host FROM user;
Copy the code

— View existing users, passwords, and allowed hosts

+------+----------+-----------+ | User | Password | Host | +------+----------+-----------+ | root | | localhost | + + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- - + 1 row in the set (0.00 SEC)Copy the code

 

Mysql > select * from ‘root’ where ‘192.168.1.100’ = ‘192.168.1.100’

Mysql > GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' IDENTIFIED BY '' WITH GRANT OPTION;Copy the code

 

Mysql > select * from Host where @’192.168.1.100′ = ‘%’;

Mysql > -- UPDATE user SET Host='192.168.1.100' WHERE user ='root' AND Host='localhost' LIMIT 1; mysql> flush privileges; Query OK, 0 rows affected (0.00 SEC)Copy the code


Changing the Root Password

mysql> use mysql
 
Database changed
 
mysql> update userset password=PASSWORD('123456')where user='root';
 
Query OK, 0 rows affected (0.00 sec)
 
Rows matched: 1  Changed: 0  Warnings: 0
 
mysql> flush privileges;
 
Query OK, 0 rows affected (0.00 sec)
Copy the code

The above three reasons have tried not to solve and you are Ali cloud server look below;

Go to ali cloud server controller to configure security group rules, click Cloud server ESC-> Network and Security -> Security Group; Add security group rule, add protocol type: MY SQL(3306); Authorization object: 0.0.0.0/0 and verify that the connection is successful, and try again later.Copy the code

This can be solved for general Ali cloud users can not connect to 3306 port.