惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - Mr.peter

Git 全量终极速记表 git常用命令汇总 Golang基础面试题 ansible是什么?怎么玩?给出常问的面试题和答案 Terraform telnet localhost 3306 -bash: telnet: command not found curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused Error: git: Failed to download resource "git.rb" Mysql 授予root在任意主机访问数据库的权限 使用Redis来处理高并发问题 go slice切片的扩容机制是什么? 使用Kubernetes时可以采取哪些最佳安全措施 Kubernetes与Docker Swarm的区别如何 k8s是怎么进行服务注册的 说说你对Job这种资源对象的了解 常用的标签分类有哪些 简述Helm及其优势 简述Kubernetes集群联邦 简述Kubernetes中,如何使用EFK实现日志的统一管理 Kubernetes 网络 Kubernetes PodSecurityPolicy
macos 开放3306端口
Mr.peter · 2025-08-11 · via 博客园 - Mr.peter

在 macOS 上开放 3306 端口(通常用于 MySQL 服务),需通过系统防火墙(pf)配置实现。以下是完整步骤,基于 macOS 内置工具 pfctl 操作:

📍 1. ‌检查 3306 端口状态‌

  • 确认 MySQL 服务是否监听 3306 端口:
    • 若输出包含 mysqld 进程,则 MySQL 正在运行;若无输出,需先启动 MySQL 服务(如 sudo /usr/local/mysql/support-files/mysql.server start12。

🔧 2. ‌配置防火墙规则‌

macOS 使用 pf(Packet Filter)防火墙。需编辑配置文件并添加规则:

  • 打开终端,备份配置文件:

    sudo cp /etc/pf.conf /etc/pf.conf.backup

  • 编辑配置文件:
  • 在文件末尾添加规则(允许 TCP 协议访问 3306 端口):

    pass in proto tcp from any to any port 3306

  • 保存并退出编辑器(Ctrl + X → Y → Enter6。

🔄 3. ‌加载防火墙规则‌

  • 应用新配置并重启防火墙:

    sudo pfctl -f /etc/pf.conf sudo pfctl -e

  • 验证规则是否生效:

    sudo pfctl -sr | grep 3306

    输出应显示 pass in proto tcp from any to any port = 330668。

🧪 4. ‌测试端口开放性‌

  • 本地测试: 若显示 Connected,表示端口开放成功。
  • 远程测试(从另一台设备): 需确保 MySQL 用户权限允许远程访问(如执行 GRANT ALL ON *.* TO 'root'@'%'413。

️ 注意事项

  • ‌安全性‌:开放 3306 端口会增加风险,建议:
    • 限制 IP 访问范围(规则中替换 from any 为 from 192.168.1.0/24)。
    • 使用强密码并定期审计 MySQL 用户权限1316。
  • ‌防火墙重启失效‌:若系统重启后规则丢失,需将规则添加到 /etc/pf.conf 并确保开机自启(可通过 sudo pfctl -E 启用)。
  • ‌第三方工具‌:若偏好图形界面,可使用 Icefloor 管理防火墙(打开 80、3306 端口)5。

完成后,MySQL 应可通过 3306 端口远程访问。如遇问题,检查 MySQL 绑定地址(确保 bind-address = 0.0.0.0)及防火墙日志 sudo pfctl -vvsr