MySQL 5.7 Remote Connection Issue: bind-address Not Working Despite Configuration


2 views

After upgrading to MySQL 5.7 on Ubuntu 16.04, I noticed that my server wasn't accepting remote connections despite setting bind-address = 0.0.0.0 in the configuration file. The server only listened on 127.0.0.1 as shown by:

lsof -Pni :3306
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  5302 mysql   25u  IPv4  37280      0t0  TCP 127.0.0.1:3306 (LISTEN)

MySQL 5.7 handles configuration files differently than previous versions. The main files to check are:

/etc/mysql/mysql.conf.d/mysqld.cnf
/etc/mysql/mariadb.conf.d/50-server.cnf
/etc/mysql/my.cnf

Note that MySQL 5.7 may ignore files in /etc/mysql/conf.d/ if they conflict with the main configuration.

Here's what finally worked for me:

  1. Edit the correct configuration file:
    sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
  2. Find and modify the bind-address line:
    [mysqld]
    bind-address = 0.0.0.0
  3. Restart MySQL service:
    sudo systemctl restart mysql

After fixing the bind-address, you still need to:

-- Create remote user (if needed)
CREATE USER 'remote_user'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'remote_user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

-- Check firewall settings
sudo ufw allow 3306/tcp

If it still doesn't work, try these diagnostics:

-- Check MySQL error log
sudo tail -f /var/log/mysql/error.log

-- Verify listening ports
sudo netstat -tulnp | grep mysql

-- Test local connection
mysql -u remote_user -p -h 127.0.0.1

-- Test remote connection (from another machine)
mysql -u remote_user -p -h server_ip

Remember that Ubuntu 16.04 uses systemd, so checking service status with systemctl status mysql can reveal startup errors.


After upgrading to MySQL 5.7 on Ubuntu 16.04, many developers encounter a frustrating scenario where the server refuses to accept remote connections despite proper bind-address configuration. Let's examine why this happens and how to properly configure network access.

In MySQL 5.7, the configuration file structure changed significantly. These are the key files that might override your settings:

/etc/mysql/mysql.conf.d/mysqld.cnf
/etc/mysql/mariadb.conf.d/50-server.cnf
/etc/mysql/conf.d/*.cnf

Here's the definitive approach to enable remote connections:

# 1. Edit the main configuration file
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

# Add or modify these lines under [mysqld]
bind-address = 0.0.0.0
skip-networking = OFF

After making changes, verify your configuration with these commands:

# Restart MySQL service
sudo systemctl restart mysql

# Check listening ports
sudo netstat -plnt | grep mysql
# OR
sudo ss -tulnp | grep mysql

Ubuntu 16.04 uses UFW firewall. Ensure port 3306 is open:

sudo ufw allow 3306/tcp
sudo ufw reload

Configuration alone isn't enough - you must also set proper user permissions:

-- Connect to MySQL locally first
mysql -u root -p

-- Create or modify user with remote access
CREATE USER 'remoteuser'@'%' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON *.* TO 'remoteuser'@'%';
FLUSH PRIVILEGES;

If problems persist, try these diagnostic commands:

# Check if MySQL is really listening
telnet your_server_ip 3306

# Verify DNS resolution
nslookup your_server_name

# Test connectivity without DNS
mysql -h your_server_ip -u remoteuser -p

For systems with multiple configuration files, you can force the binding by creating a dedicated file:

sudo nano /etc/mysql/conf.d/bind-address.cnf

[mysqld]
bind-address = ::
bind-address = 0.0.0.0
skip-name-resolve