You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debian 9下MariaDB运行但netstat未检测到3306端口监听求助

Why netstat -anp | grep 3306 Shows Nothing But MariaDB is Running (Debian 9)

Hey there! Let's break down why this is happening and how to fix it—it's a super common gotcha with local MariaDB connections.

The Core Issue: You're Connecting via Unix Socket, Not TCP Port 3306

When you run mysql without specifying a host (-h), the client defaults to using a Unix domain socket instead of the TCP port 3306. MariaDB might be configured to only listen on this socket (and not the TCP port), which explains why netstat doesn't pick up port 3306 but you can still connect locally.

Step 1: Verify MariaDB's Network Configuration

First, let's check how MariaDB is set up. Run this command in your terminal:

mysql -e "SHOW VARIABLES LIKE '%socket%'; SHOW VARIABLES LIKE '%bind_address%'; SHOW VARIABLES LIKE '%skip_networking%';"

Look for these key outputs:

  • skip_networking: If this is set to ON, MariaDB is not listening on any TCP port at all—it only accepts connections via the Unix socket.
  • bind_address: If this is set to 127.0.0.1 but skip_networking is OFF, it should listen on TCP port 3306 locally. A blank or NULL value might mean it's only using the socket.
  • socket: This shows the path to the Unix socket file (usually /var/run/mysqld/mysqld.sock).

Step 2: Check for Unix Socket Listener

Since netstat -anp only shows TCP/UDP ports by default, use this command to see the Unix socket listener:

netstat -anpx | grep mysql

Or use the more modern ss tool (often more reliable than netstat):

ss -lx | grep mysql

You should see a line referencing the socket path from the earlier SHOW VARIABLES output.

Step 3: Enable TCP Port 3306 (If You Need It)

If you want MariaDB to listen on TCP port 3306 (for example, to connect remotely or use TCP locally), follow these steps:

  1. Open your MariaDB server configuration file. On Debian 9, this is typically:
    nano /etc/mysql/mariadb.conf.d/50-server.cnf
    
  2. Look for the line skip-networking—if it exists, comment it out by adding a # at the start:
    # skip-networking
    
  3. Ensure the bind_address line is set to the IP you want to listen on. For local-only TCP connections:
    bind-address = 127.0.0.1
    
    For allowing remote connections (use with caution, and secure your setup with firewalls and strong credentials):
    bind-address = 0.0.0.0
    
  4. Restart MariaDB to apply changes:
    systemctl restart mariadb
    
  5. Now run netstat -anp | grep 3306 again—you should see a line like:
    tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1234/mysqld
    

Quick Test to Confirm TCP vs Socket Connection

  • Try connecting via TCP explicitly:
    mysql -h 127.0.0.1
    
    If this fails, MariaDB isn't listening on TCP port 3306. If it works, then both socket and TCP connections are enabled.

内容的提问来源于stack exchange,提问作者tomsk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:28:34