Home > Database > Mysql Tutorial > Why Can't I Remotely Connect to My MySQL Server on Ubuntu?

Why Can't I Remotely Connect to My MySQL Server on Ubuntu?

Linda Hamilton
Release: 2024-12-14 07:15:15
Original
449 people have browsed it

Why Can't I Remotely Connect to My MySQL Server on Ubuntu?

Remote Connection Issues with MySQL on Ubuntu

Despite granting remote access privileges to a user, users face difficulties connecting remotely to their MySQL server. This article addresses these issues and provides comprehensive solutions.

Troubleshooting Remote Connection Errors

One common issue is forgetting to uncomment the bind-address line in the MySQL configuration file. For MySQL versions 5.6 and below, this line is found in /etc/mysql/my.cnf, while for versions 5.7 and above, it is in /etc/mysql/mysql.conf.d/mysqld.cnf. Uncomment the line and assign it to the server's IP address or 0.0.0.0 for unrestricted access.

Checking MySQL Connections

To verify that MySQL is listening on the correct IP address, run

lsof -i -P | grep :3306
Copy after login

This should display the listening port with the server's IP address. If this fails, ensure MySQL is indeed listening on the specified IP address.

Granting Remote Access Privileges

Even with the correct bind-address, remote users may still face access issues. To resolve this, the user must be created with identical privileges for both localhost and %. For example:

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';
Copy after login

Next, grant the user all privileges on *.*:

GRANT ALL ON *.* TO 'myuser'@'localhost';
GRANT ALL ON *.* TO 'myuser'@'%';
Copy after login

Additional Troubleshooting

If lsof does not work, consider installing it for your specific Linux distribution. Additionally, check the configuration file /etc/mysql/mariadb.conf.d/50-server.cnf for any conflicting bind-address settings. By implementing these solutions, users can establish successful remote connections to their MySQL server on Ubuntu.

The above is the detailed content of Why Can't I Remotely Connect to My MySQL Server on Ubuntu?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template