当前位置:网站首页>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 .
边栏推荐
- Recommendation of good books on learning QT programming
- [combinatorial mathematics] counting model, common combinatorial numbers and combinatorial identities**
- 跟我学企业级flutter项目:简化框架demo参考
- Informatics Olympiad all in one YBT 1175: divide by 13 | openjudge noi 1.13 27: divide by 13
- Explore Netease's large-scale automated testing solutions see here see here
- [combinatorics] polynomial theorem (polynomial coefficients | full arrangement of multiple sets | number of schemes corresponding to the ball sub model | polynomial coefficient correlation identity)
- Extraction of the same pointcut
- CC2530 common registers for port interrupts
- Unreal_ Datatable implements ID self increment and sets rowname
- What is the difference between 14Cr1MoR container plate and 14Cr1MoR (H)? Chemical composition and performance analysis of 14Cr1MoR
猜你喜欢
消息队列消息丢失和消息重复发送的处理策略
What material is 12cr1movr? Chemical property analysis of pressure vessel steel plate 12cr1movr
NLP four paradigms: paradigm 1: fully supervised learning in the era of non neural networks (Feature Engineering); Paradigm 2: fully supervised learning based on neural network (Architecture Engineeri
斑马识别成狗,AI犯错的原因被斯坦福找到了
Daily code 300 lines learning notes day 10
Interviewer: how does the JVM allocate and recycle off heap memory
What is the material of sa302grc? American standard container plate sa302grc chemical composition
Simulink oscilloscope data is imported into Matlab and drawn
Add color to the interface automation test framework and realize the enterprise wechat test report
线程池执行定时任务
随机推荐
MySQL Basics
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
MongoDB 的安装和基本操作
Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
Explore Cassandra's decentralized distributed architecture
utfwry. Dat PHP, about ThinkPHP's method of IP location using utfwry address Library
QT serial port UI design and solution to display Chinese garbled code
IDEA-配置插件
Pointcut expression
LeetCode 1656. Design ordered flow
远程办公之如何推进跨部门项目协作 | 社区征文
Cocos Creator 2.x 自动打包(构建 + 编译)
[sword finger offer] 58 - I. flip the word order
什么是质押池,如何进行质押呢?
Basis of target detection (IOU)
There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them
CC2530 common registers for crystal oscillator settings
Custom plug-in construction and use of QT plug-in
CC2530 common registers for timer 1
Everyone in remote office works together to realize cooperative editing of materials and development of documents | community essay solicitation