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

无法从Ubuntu服务器连接Linux端MySQL服务器的排查求助

Troubleshooting MySQL Connection Issues from Ubuntu Server

Got it, let’s dive into the less obvious MySQL configurations that might be blocking your connection from the Ubuntu server. You’ve covered the basics (user grants, bind-address, localhost restrictions), so let’s check these often-overlooked items:

  • Check for skip-networking in MySQL config
    This is a common gotcha—if skip-networking is enabled in your MySQL config file, MySQL will completely ignore all network connections and only allow local socket access. To fix this:

    1. Open your MySQL config file (usually /etc/mysql/my.cnf or /etc/mysql/mysql.conf.d/mysqld.cnf).
    2. Look for the line skip-networking—if it exists, comment it out with a #.
    3. Restart the MySQL service: sudo systemctl restart mysql
  • Verify your user’s host authorization scope
    Even if you granted full privileges, you need to ensure the user is authorized to connect from your Ubuntu server’s IP (or any IP, for testing). Run these commands on the MySQL server:

    SELECT user, host FROM mysql.user;
    

    Check if your target user has a host value of % (any host) or your Ubuntu server’s specific IP. If not, re-grant the privileges with the correct host:

    GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    

    Note: Using % is great for testing—once you confirm the connection works, restrict it to your Ubuntu server’s IP for security.

  • Confirm MySQL is listening on the correct port and IP
    Make sure MySQL is actually listening for connections on the expected port (default 3306) and not just the local loopback. Run this on the MySQL server:

    ss -tulpn | grep mysql
    

    Look for a line like LISTEN 0 128 0.0.0.0:3306 0.0.0.0:*—this means it’s listening on all IPs. If you see 127.0.0.1:3306, your bind-address config isn’t taking effect—double-check the config file and restart MySQL.

  • Check require_secure_transport setting
    If MySQL requires SSL for connections but your Ubuntu client isn’t using it, you’ll get a connection error. Check the setting on the MySQL server:

    SHOW VARIABLES LIKE 'require_secure_transport';
    

    If it returns ON, you have two options:

    1. Connect with SSL enabled from Ubuntu: mysql -h <mysql-server-ip> -u <user> -p --ssl-mode=REQUIRED
    2. Disable the requirement (for testing) by adding require_secure_transport = OFF to your MySQL config and restarting the service.
  • Dig into MySQL error logs
    This is the most reliable way to find the root cause. Check the latest entries in MySQL’s error log (usually /var/log/mysql/error.log):

    sudo tail -n 50 /var/log/mysql/error.log
    

    Look for lines like Access denied for user 'xxx'@'your-ubuntu-ip' or Can't connect to MySQL server on 'xxx'—these will tell you exactly what’s blocking the connection.

  • Verify Ubuntu client compatibility
    If your Ubuntu server has an outdated MySQL client, it might fail to connect to a newer MySQL server. Upgrade the client with:

    sudo apt update && sudo apt upgrade mysql-client
    

    Then try connecting again with the standard command: mysql -h <mysql-server-ip> -u <user> -p

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:23:34