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

Javascript Basics: Detailed Explanation of Operators and Flow Control

Table of contents 1. Operator 1.1 Arithmetic oper...

Analysis of Mysql data migration methods and tools

This article mainly introduces the analysis of My...

Binary Search Tree Algorithm Tutorial for JavaScript Beginners

Table of contents What is a Binary Search Tree (B...

How to use libudev in Linux to get USB device VID and PID

In this article, we will use the libudev library ...

How to install docker on Linux system and log in to docker container through ssh

Note: I use Centos to install docker Step 1: Inst...

How to use JavaScript strategy pattern to validate forms

Table of contents Overview Form validation withou...

Seven different color schemes for website design experience

The color matching in website construction is ver...

Vue calls the PC camera to realize the photo function

This article example shares the specific code of ...

How to solve the problem of forgetting the root password of Mysql on Mac

I haven't used mysql on my computer for a lon...

Detailed explanation of HTML style tags and related CSS references

HTML style tag style tag - Use this tag when decl...

Detailed explanation of how to use eslint in vue

Table of contents 1. Description 2. Download rela...

Newbies quickly learn the steps to create website icons

<br />Original URL: http://www.lxdong.com/po...

The process of installing and configuring nginx in win10

1. Introduction Nginx is a free, open source, hig...

Several ways to implement "text overflow truncation and omission" with pure CSS

In our daily development work, text overflow, tru...

Detailed explanation of how Angular handles unexpected exception errors

Written in front No matter how well the code is w...