Home Database Mysql Tutorial linux下mysql开启远程访问权限及防火墙开放3306端口_MySQL

linux下mysql开启远程访问权限及防火墙开放3306端口_MySQL

Jun 01, 2016 pm 01:01 PM
Permissions port firewall

开启mysql的远程访问权限

默认mysql的用户是没有远程访问的权限的,因此当程序跟数据库不在同一台服务器上时,我们需要开启mysql的远程访问权限。

主流的有两种方法,改表法和授权法。

相对而言,改表法比较容易一点,个人也是比较倾向于使用这种方法,因此,这里只贴出改表法

1、登陆mysql

mysql -u root -p 
Copy after login

2、修改mysql库的user表,将host项,从localhost改为%。%这里表示的是允许任意host访问,如果只允许某一个ip访问,则可改为相应的ip,比如可以将localhost改为192.168.1.123,这表示只允许局域网的192.168.1.123这个ip远程访问mysql。

mysql> use mysql; 
mysql> update user set host = '%' where user = 'root'; 
mysql> select host, user from user; 
mysql> flush privileges; 
Copy after login

防火墙开放3306端口

1、打开防火墙配置文件

vi  /etc/sysconfig/iptables
Copy after login

2、增加下面一行

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
Copy after login

3、重启防火墙

service  iptables restart
Copy after login

注意:增加的开放3306端口的语句一定要在icmp-host-prohibited之前

附:个人配置

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -p icmp -j ACCEPT
-A FORWARD -i lo -j ACCEPT
-A FORWARD -i eth0 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Soundbar detected as monitor screen on Windows PC [Fix] Soundbar detected as monitor screen on Windows PC [Fix] Feb 19, 2024 pm 11:42 PM

On Windows PCs, some users have discovered that the Soundbar is recognized as a monitor when connected to the HDMI port. This may cause some confusion, but the solution is not the only one. How to Connect a Soundbar to a PC via HDMI Most soundbars use HDMI, optical, or 3.5mm audio connections. If your soundbar only supports HDMI connections, it must be connected to an HDMI port labeled HDMIARC. Many TVs or monitors are usually equipped with multiple HDMI ports, one of which should support the ARC protocol that complies with the HDMI standard. In other words, HDMI is an interface used to transmit audio and video. If the device does not have an HDMI port, consider using a monitor.

Enable root permissions with one click (quickly obtain root permissions) Enable root permissions with one click (quickly obtain root permissions) Jun 02, 2024 pm 05:32 PM

It allows users to perform more in-depth operations and customization of the system. Root permission is an administrator permission in the Android system. Obtaining root privileges usually requires a series of tedious steps, which may not be very friendly to ordinary users, however. By enabling root permissions with one click, this article will introduce a simple and effective method to help users easily obtain system permissions. Understand the importance and risks of root permissions and have greater freedom. Root permissions allow users to fully control the mobile phone system. Strengthen security controls, customize themes, and users can delete pre-installed applications. For example, accidentally deleting system files causing system crashes, excessive use of root privileges, and inadvertent installation of malware are also risky, however. Before using root privileges

Win11 firewall advanced settings gray solution Win11 firewall advanced settings gray solution Dec 24, 2023 pm 07:53 PM

When setting up the firewall, many friends found that their win11 firewall advanced settings were grayed out and unable to be clicked. This may be caused by not adding a control unit, or by not opening the advanced settings in the correct way. Let’s take a look at how to solve it. Win11 firewall advanced settings gray method one: 1. First, click the start menu below, search and open "Control Panel" at the top 2. Then open "Windows Defender Firewall" 3. After entering, you can open "Advanced Settings" in the left column . Method 2: 1. If the above method cannot be opened, you can right-click "Start Menu" and open "Run" 2. Then enter "mmc" and press Enter to confirm opening. 3. After opening, click on the upper left

How to enable or disable firewall on Alpine Linux? How to enable or disable firewall on Alpine Linux? Feb 21, 2024 pm 12:45 PM

On AlpineLinux, you can use the iptables tool to configure and manage firewall rules. Here are the basic steps to enable or disable the firewall on AlpineLinux: Check the firewall status: sudoiptables -L If the output shows rules (for example, there are some INPUT, OUTPUT, or FORWARD rules), the firewall is enabled. If the output is empty, the firewall is currently disabled. Enable firewall: sudoiptables-PINPUTACCEPTsudoiptables-POUTPUTACCEPTsudoiptables-PFORWARDAC

How to remove the firewall logo on the Win10 desktop icon? How to remove the firewall logo on the Win10 desktop icon? Jan 01, 2024 pm 12:21 PM

Many friends who use win10 system find that there is a firewall logo on the icon on the computer desktop. What is going on? This makes many friends with obsessive-compulsive disorder particularly uncomfortable. In fact, we only need to open the control panel and click " It can be solved by changing "Change User Account Control Settings". Let's take a look at the specific tutorial. How to cancel the firewall logo on the desktop icon in Windows 10 1. First, right-click the Start menu button next to the computer startup screen, and then select the Control Panel function from the pop-up menu. 2. Then select the "User Account" option and select the "Change User Account Control Settings" item from the new interface that appears. 3. After adjusting the slider in the window to the bottom, click Confirm to exit.

Fix AHCI Port 0 Device Error on Windows Computer Fix AHCI Port 0 Device Error on Windows Computer Feb 19, 2024 pm 12:45 PM

If you encounter an AHCI port 0 device error every time you start your computer, you need to follow the methods provided in this article to solve the problem. What is AHCI port 0 device error? AHCI device errors are reported by the BIOS. SMART has indicated that the hard drive on port 0 is faulty and may not be accessible. The hard drive may have problems at any time. If it is a desktop computer, it is recommended to try changing the hard drive connection port. If the problem persists, it may be a problem with the hard drive itself. You can run a disk check tool, disable the failed hard drive and check the ports to resolve this issue. Fixing AHCI Port 0 Device Errors on Windows Computers Typically, AHCI Port0 device errors do not originate from operating system issues, but rather from the hard drive failing on port 0.

How to set permission access in QQ space How to set permission access in QQ space Feb 23, 2024 pm 02:22 PM

How to set permission access in QQ space? You can set permission access in QQ space, but most friends don’t know how to set permission access in QQ space. Next is the diagram of how to set permission access in QQ space brought by the editor for users. Text tutorial, interested users come and take a look! QQ usage tutorial QQ space how to set permission access 1. First open the QQ application, click [Avatar] in the upper left corner of the main page; 2. Then expand the personal information area on the left and click the [Settings] function in the lower left corner; 3. Enter the settings page Swipe to find the [Privacy] option; 4. Next in the privacy interface, select the [Permission Settings] service; 5. Then challenge to the latest page and select [Space Dynamics]; 6. Set up in QQ Space again

How to fix UFW status showing as inactive in Linux How to fix UFW status showing as inactive in Linux Mar 20, 2024 pm 01:50 PM

UFW, also known as Uncomplex Firewall, is adopted by many Linux distributions as their firewall system. UFW is designed to make it easy for novice users to manage firewall settings through both the command line interface and the graphical user interface. A UFW firewall is a system that monitors network traffic according to set rules to protect the network from network sniffing and other attacks. If you have UFW installed on your Linux system but its status shows as inactive, there could be several reasons. In this guide, I will share how to resolve the UFW firewall inactive issue on Linux systems. Why UFW Shows Inactive Status on Linux Why UFW Is Inactive by Default on Linux How to Inactive on Linux

See all articles