当前位置:网站首页>How to allow remote connection to MySQL server on Linux system?
How to allow remote connection to MySQL server on Linux system?
2022-07-03 16:47:00 【wljslmz】
stay Linux Installation on system MySQL After the server , By default, it only accepts incoming connections from itself ( That is, the loopback address 127.0.0.1).
If you just try to read or write information from a database on the same server , Then this default configuration works , therefore , Put their website and MySQL Users whose servers are hosted on the same machine do not need to make any additional configuration to allow remote connections .
If you want to allow remote connections to your MySQL The server , Because you have other computers and / Or users who need to access the data , You need to MySQL The service is bound to the public on the server IP Address , And may allow incoming MySQL Connect through the system firewall .
In this tutorial , We will guide you step by step in Linux Remote connection to... Is allowed on the system MySQL The server , These instructions should be independent of any Linux Distribution version .
In this tutorial , You will learn :
- How to allow remote connections to MySQL The server
- How to allow remote connection to... Through the system firewall MySQL
- How to create or change MySQL Users to allow remote connections
Allow remote connections to your MySQL Database is a three-step process .
First , We need to go through MySQL Configure the public binding address in the configuration file to MySQL The service is set to be accessible from a remote machine .
secondly , We need to allow remote access through our system firewall , By default ,MySQL In the port 3306 Up operation , Therefore, you need to allow connections to this port .
Third , We need to create a new user or edit an existing user , So that it can be remotely IP Address access , We can choose to allow all IP Address or only allow specific IP Address .
To configure MySQL Binding address
We will open /etc/mysql/mysql.cnf
File start . Use root jurisdiction , stay nano Or open it in your favorite text editor .
$ sudo nano /etc/mysql/mysql.cnf
Find this section bind-address The settings below [mysqld]
, By default , This should currently be configured as a loopback address 127.0.0.1. Delete the address and make your server public IP Put the address in its place . We will only 10.1.1.1 For example .
[mysqld]
bind-address = 10.1.1.1
if necessary , You can use... Instead 0.0.0.0 Binding address , This is a wildcard , The service should be bound to all accessible interfaces . This is not recommended , But if you encounter problems in the future , This is very helpful for troubleshooting .
[mysqld]
bind-address = 0.0.0.0
After making changes , Save your changes to a file and exit . then , You will need to restart MySQL Services for changes to take effect .
$ sudo systemctl restart mysql
On some distributions , This service may be called mysqld:
$ sudo systemctl restart mysqld
Allow remote access through the firewall
Suppose you are MySQL The server uses the port 3306, We need to allow it to pass through the system firewall . The commands you need to execute will depend on the distribution you use . Please refer to the list below or adjust the commands as needed to match the firewall syntax of your own system .
stay Ubuntu System and other uses ufw( Simple firewall ) On the system :
$ sudo ufw allow mysql
In the use of firewalld Of Red Hat、CentOS、Fedora And derivative systems :
$ sudo firewall-cmd --zone=public --add-service=mysql --permanent
$ sudo firewall-cmd --reload
And old... For any system iptables command :
$ sudo iptables -A INPUT -p tcp --dport 3306 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
Allow remote connections to specific users
Now? MySQL The service can accept incoming connections and our firewall will allow them to pass , We just need to configure our users to accept remote connections .
use first root Account open MySQL.
$ sudo mysql
perhaps , In some configurations , You may need to enter the following command and provide your root password :
$ mysql -u root -p
If you have created a user , And the user needs to be configured to be able to remote IP Address access , We can use MySQLRENAME USER
command . We will make our wljslmz Users can start from IP Address access 10.150.1.1, But adjust it according to your own configuration .
mysql> RENAME USER 'wljslmz'@'localhost' TO 'wljslmz'@'10.150.1.1';
perhaps , If you are creating this user for the first time , We will use this CREATE USER
command . Please be sure to use the following user name 、IP Replace the address and password with your own .
mysql> CREATE USER 'wljslmz'@'10.150.1.1' IDENTIFIED BY 'password_here';
If you want your users to be able to from any IP Address access , Then you can % Used in commands rather than specific IP Address . Here's how to edit an existing user to be available from any IP visit :
mysql> RENAME USER 'wljslmz'@'localhost' TO 'wljslmz'@'%';
Here's how to create one that can be from any IP Address access new users :
mysql> CREATE USER 'wljslmz'@'%' IDENTIFIED BY 'password_here';
Everything here is its . After granting users access to one or more databases , You will be able to access the database remotely using account credentials .
summary
In this tutorial , We learned how to allow remote connections to Linux On the system MySQL service . This is to make the service accessible 、 Allow connection and creation of accessible through firewall MySQL Three part process of account . because MySQL The working principle is basically the same in all distributions , So these steps should be available to everyone .
边栏推荐
- There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them
- 8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
- Explore Cassandra's decentralized distributed architecture
- 比亚迪、长城混动市场再“聚首”
- Caching mechanism of Hibernate / session level caching mechanism
- 关于学习Qt编程的好书精品推荐
- What material is sa537cl2? Analysis of mechanical properties of American standard container plate
- Aike AI frontier promotion (7.3)
- Top k questions of interview
- Extraction of the same pointcut
猜你喜欢
CC2530 common registers for port interrupts
Mysql 单表字段重复数据取最新一条sql语句
Interviewer: how does the JVM allocate and recycle off heap memory
什么是质押池,如何进行质押呢?
Explore Netease's large-scale automated testing solutions see here see here
Learn from me about the enterprise flutter project: simplified framework demo reference
Aike AI frontier promotion (7.3)
Netease UI automation test exploration: airtest+poco
TCP congestion control details | 3 design space
ThreeJS 第二篇:顶点概念、几何体结构
随机推荐
[combinatorics] recursive equation (example 1 of recursive equation | list recursive equation)
Golang decorator mode and its use in NSQ
PHP converts a one-dimensional array into a two-dimensional array
Idea configuration plug-in
Network security web penetration technology
斑马识别成狗,AI犯错的原因被斯坦福找到了
Informatics Olympiad all in one YBT 1175: divide by 13 | openjudge noi 1.13 27: divide by 13
Web crawler knowledge day03
JSON 与 BSON 区别
Caching mechanism of Hibernate / session level caching mechanism
13mnnimo5-4 German standard steel plate 13MnNiMo54 boiler steel 13MnNiMo54 chemical properties
[combinatorics] non descending path problem (number of non descending paths with constraints)
What is the difference between 14Cr1MoR container plate and 14Cr1MoR (H)? Chemical composition and performance analysis of 14Cr1MoR
[Jianzhi offer] 64 Find 1+2+... +n
What is the pledge pool and how to pledge?
于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日
Characteristic polynomial and constant coefficient homogeneous linear recurrence
香港理工大学|数据高效的强化学习和网络流量动态的自适应最优周界控制
CC2530 common registers for serial communication
智慧之道(知行合一)