Mysql database remote connection

If you want to connect to the database remotely

An error occurred,,,

Firewall open ports,,, CentOS 7.0 uses firewall as firewall by default, and iptables must be reset

1. Directly close the firewall
systemctl stop firewalld.service #Stop firewall
systemctl disable firewalld.service #Prohibit firewall startup

2. Set iptables service
yum -y install iptables-services
If you want to modify the firewall configuration, such as adding firewall port 3306
vi /etc/sysconfig/iptables 
to add rules
-A INPUT -m state --state NEW -m tcp -p tcp -- dport 3306 -j ACCEPT

save and exit
systemctl restart iptables.service #Restart the firewall to make the configuration take effect
systemctl enable iptables.service #Set the firewall to start on boot

 

 

One is the firewall problem,,, https://www.cnblogs.com/lightsrs/p/7842299.html

1.# grep "password" /var/log/mysqld.log

2.# mysql -uroot -p

3. grant all privileges on *.* to 'root'@'%' identified by 'your database password';

4.flush privileges;

5.exit;

shell > netstat -apn View all port information, as shown in the figure below, the port number of mysqld service Listen is 3306, of course, you can also run mysql > show variables like 'port' in MySQL;

 netstat -apn | grep 3306

find / -name my.cnf

vim /etc/my.cnf

The default firewall of CentOS7 is firewall, and it is not turned on by default.

 systemctl start firewalld start friewall

systemctl status firewalld View firewall startup status

firewall-cmd --zone=public --add-port=3306/tcp --permanent open port 3306

Then restart firewalld #firewall-cmd --reload

Use # firewall-cmd --query-port=3306/tcp to check whether port 3306 has been opened. If yes, it means that the firewall has opened the port.

Check whether the setting is successful Enter the database, and exit after writing

 

The second is whether Alibaba Cloud itself has opened port 3306 https://jingyan.baidu.com/article/03b2f78c31bdea5ea237ae88.html

Log in to Alibaba Cloud, enter the console, click ECS, enter the server console, click the server you want to select, enter the server instance list, find the instance you want to add ports, click More, click More, and find it in the list Security group configuration, and click Configure Rules to jump to the page as shown in the figure. The circled part is the port that has been opened. If you want to add a new port, click Add Security Group Rule and enter the content in the pop-up window. For example, add port 3306, as shown in the figure, (it must be in the form of 3306/3306), click OK and see if there is an additional port of 22 in your security group rule. If so, congratulations that you have successfully opened it.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325300061&siteId=291194637