How to solve the problem of remote connectivity mysql appears Can not connect to MySQL server on (111 "Connection refused") of

Transfer:
https://www.jianshu.com/p/24bd98112d80
https://www.cnblogs.com/myblog1993/p/10560679.html

1 open MySQL remote connections

MySQL root user to log in:

# mysql -u root -p

Run empowerment:

MySQL> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'password' WITH GRANT OPTION;

MySQL> flush privileges;

password for the MySQL root password corresponding to the user.

Restart MySQL:

方式一:
# /etc/init.d/mysql restart

方式二:
# service mysql restart

2 Open the database default port

First, use the following command to check port 3306 (MySQL default port number, the absence of change is 3306) whether the opening:

netstat -an | grep 3306

If the display is as follows, indicating that MySQL port is currently listening only local connections 127.0.0.1. Then you need to modify the MySQL configuration file.

tcp	 0	0	127.0.0.1:3306	0.0.0.0:*	LISTEN

Modify the MySQL configuration file:

# cd /etc/mysql/mysql.conf.d
# vim mysqld.cnf

Here Insert Picture Description
MySQL's default port can also be modified by the file.

Wherein the bind-address = 127.0.0.1 commented. Then restart MySQL.

After the above two steps you can re-try if you can access, if you still can not access, it may be the reason the firewall.

3 Check the firewall

You can turn off the firewall test, then if you can turn off access, it may be that MySQL port is not open, turn off the firewall and open ports command is as follows:

Turn off the firewall:

sudo ufw stop

Open port 3306:

sudo ufw allow 3306

Appendix 4

UFW is a host under the Ubuntu iptables based firewall configuration tool (iptables to handle low-level calls), easy to use.

installation method
sudo apt install ufw
Instructions

ufw command list:
Here Insert Picture Description

Common ufw command Introduction

Enable Firewall

sudo ufw enable
sudo ufw default deny
## 作用:开启了防火墙并随系统启动同时关闭所有外部对本机的访问(本机访问外部正常)。

Role: Turn on the firewall and start with the system simultaneously closing all external access to the machine (the machine to access the external normal).

Turn off the firewall

sudo ufw stop

Check firewall status

sudo ufw status

View the list of applications

sudo ufw app list

Increase licensing rules permit ssh port

sudo ufw allow ssh

Allow external access port 80

sudo ufw allow 80

Prohibit external access port 80

sudo ufw delete allow 80

This allows access to all local IP port

sudo ufw allow from 192.168.1.1

RFC1918 allows all network (LAN / WLAN) access the host (/ 8, / 16, / 12 is a hierarchical network)

sudo ufw allow from 10.0.0.0/8
sudo ufw allow from 172.16.0.0/12
sudo ufw allow from 192.168.0.0/16
Published 21 original articles · won praise 11 · views 20000 +

Guess you like

Origin blog.csdn.net/hexf9632/article/details/103890046