How to Configure MySQL to Listen on TCP Connections for Remote Access
Admin
How to Configure MySQL to Listen on TCP Connections
By default, MySQL only accepts connections from the localhost (127.0.0.1). If you want to allow remote connections over TCP, you need to change its configuration.
Step 1: Edit MySQL Configuration File
Open the MySQL config file, usually located at /etc/mysql/my.cnf
or /etc/mysql/mysql.conf.d/mysqld.cnf
depending on your system.
Find the line that starts with bind-address
and comment it out by adding a #
at the beginning, like this:
#bind-address = 127.0.0.1
Step 2: Restart MySQL Service
After saving the changes, restart MySQL to apply the new configuration:
sudo systemctl restart mysql
Important Security Notes
- Allowing MySQL to listen on all interfaces can expose your database to potential attacks.
- Make sure to secure MySQL users with strong passwords and proper privileges.
- Consider using a firewall or VPN to restrict access to your MySQL server.
Conclusion
Changing MySQL to listen on TCP connections enables remote database access, which can be useful for distributed applications and remote management. Always balance accessibility with security.