How to enable MySQL remote connection

How to enable MySQL remote connection

For security reasons, MySql-Server only allows the local machine (localhost, 127.0.0.1) to connect and access. This is not a problem for the website architecture where the Web-Server and MySql-Server are on the same server.

However, as website traffic increases, the later server architecture may place the Web-Server and MySql-Server on separate servers in order to achieve greater performance improvements. At this time, MySql-Server must be modified to allow the Web-Server to connect remotely.

With the remote connection enabled, you don't have to log in to the server every time for the subsequent management and maintenance of the database. You can use a graphical interface (such as phpMyAdmin) for remote management.

To open a remote connection to MySql-Server, you need to authorize access to the IP address and server port:

1. Log in to Mysql-Server on the server and connect to the local mysql (only local connections are allowed by default, and remote access to phpMyAdmin is actually equivalent to local connections):

[root@iZq2mvq6snkcniZ ~]# mysql -uroot -p123456

123456 is the password, please use your database password. Here we use command line login as an example, but you can also use a graphical interface.

2. Modify the Mysql-Server user configuration:

MySQL [(none)]>use mysql;
#View existing users, passwords and hosts allowed to connect MySQL [mysql]> SELECT User, Password, Host FROM user;  
+------+-------------------------------------------+-----------+
| User | Password | Host |
+------+-------------------------------------------+-----------+
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | localhost |
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | 127.0.0.1 |
+------+-------------------------------------------+-----------+
2 rows in set (0.00 sec)

#Setting it to be accessible to all IPs is dangerous and not recommended.
MySQL [mysql]> UPDATE user SET Host=@'%' where user='root' AND Host='localhost' LIMIT 1;  
MySQL [mysql]> flush privileges;
#View the existing users, passwords and hosts allowed to connect again MySQL [mysql]> SELECT User, Password, Host FROM user;  
+------+-------------------------------------------+-----------+
| User | Password | Host |
+------+-------------------------------------------+-----------+
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | |
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | 127.0.0.1 |
+------+-------------------------------------------+-----------+

3. Finally, please note that on Linux servers, port 3306 is closed by default and remote access is not allowed. Therefore, you need to open port 3306 for MySQL remote connection. The port opening method is:

[root@iZq2mvq6snkcniZ ~]# iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
[root@iZq2mvq6snkcniZ ~]# service iptables save

At this point, you can actually access the database remotely. An example of remote access is:

Other command references:

Next we configure the root user: the password is empty, and only connections from 192.168.1.100 are allowed.

The above is the detailed content of how to enable MySQL remote connection. For more information about enabling MySQL remote connection, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Solve the problem of error 10038 when connecting to MySQL remotely in Navicat
  • Detailed explanation of Navicat's slow remote connection to MySQL
  • How to install MySql in CentOS 8 and allow remote connections
  • Tutorial on installing MySQL with Docker and implementing remote connection
  • Solution to the problem that Navicat cannot remotely connect to MySql server
  • How to solve the 10060 unknow error when Navicat remotely connects to MySQL
  • Docker deploys mysql to achieve remote connection sample code
  • Navicat remote connection to MySQL implementation steps analysis
  • Tutorial on installing MySql5.7 in CentOS7.2 and enabling remote connection authorization
  • How to authorize remote connections in MySQL in Linux

<<:  Vue front-end development auxiliary function state management detailed example

>>:  How to call a piece of HTML code together on multiple HTML pages

Recommend

How to correctly modify the ROOT password in MySql8.0 and above versions

Deployment environment: Installation version red ...

JavaScript implements displaying a drop-down box when the mouse passes over it

This article shares the specific code of JavaScri...

Web page experience: planning and design

1. Clarify the design direction <br />First,...

Solution to SNMP4J server connection timeout problem

Our network management center serves as the manag...

Summary of the differences and usage of plugins and components in Vue

The operating environment of this tutorial: Windo...

Linux operation and maintenance basics httpd static web page tutorial

Table of contents 1. Use the warehouse to create ...

How to use Vue-router routing

Table of contents 1. Description 2. Installation ...

How to skip errors in mysql master-slave replication

1. Traditional binlog master-slave replication, s...

MySQL server 5.7.20 installation and configuration method graphic tutorial

This article records the installation and configu...

Website redesign is a difficult task for every family

<br />Every family has its own problems, and...

Mysql query database capacity method steps

Query the total size of all databases Here’s how:...

MySQL Series 7 MySQL Storage Engine

1. MyISAM storage engine shortcoming: No support ...