无法从Ubuntu服务器连接Linux端MySQL服务器的排查求助
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-networkingin MySQL config
This is a common gotcha—ifskip-networkingis enabled in your MySQL config file, MySQL will completely ignore all network connections and only allow local socket access. To fix this:- Open your MySQL config file (usually
/etc/mysql/my.cnfor/etc/mysql/mysql.conf.d/mysqld.cnf). - Look for the line
skip-networking—if it exists, comment it out with a#. - Restart the MySQL service:
sudo systemctl restart mysql
- Open your MySQL config file (usually
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
hostvalue 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 mysqlLook 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 see127.0.0.1:3306, yourbind-addressconfig isn’t taking effect—double-check the config file and restart MySQL.Check
require_secure_transportsetting
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:- Connect with SSL enabled from Ubuntu:
mysql -h <mysql-server-ip> -u <user> -p --ssl-mode=REQUIRED - Disable the requirement (for testing) by adding
require_secure_transport = OFFto your MySQL config and restarting the service.
- Connect with SSL enabled from Ubuntu:
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.logLook for lines like
Access denied for user 'xxx'@'your-ubuntu-ip'orCan'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-clientThen try connecting again with the standard command:
mysql -h <mysql-server-ip> -u <user> -p
内容的提问来源于stack exchange,提问作者Kashif Anwar

