How to configure MySQL to allow remote access?

To enable remote access to MySQL, the following configuration steps need to be taken:

  1. Modify the MySQL configuration file by opening the my.cnf file (usually located at /etc/mysql/my.cnf on Linux or C:\Program Files\MySQL\MySQL Server X.X\my.ini on Windows), locate the bind-address line, and comment it out or change it to 0.0.0.0. This will allow MySQL to accept remote connections from any IP address.
  2. Grant remote access permission: log in to the MySQL server and execute the following command:
GRANT ALL PRIVILEGES ON *.* TO '用户名'@'远程IP地址' IDENTIFIED BY '密码' WITH GRANT OPTION;

In this case, ‘username’ is the username that will be granted remote access permission, ‘remote IP address’ is the allowed remote IP address for access, and ‘password’ is the user’s password. Please replace these values with the actual ones. If you want to allow remote access from any IP address, you can set ‘remote IP address’ as ‘%’.

  1. Refresh permissions: Run the following command to refresh MySQL permissions for the changes to take effect:
FLUSH PRIVILEGES;
  1. Set up firewall: If there is a firewall running on the MySQL server, make sure to allow the port used for connecting to MySQL (usually 3306) to pass through the firewall.

After completing the above configuration, MySQL will allow remote access from specified IP addresses or any IP address. Please be aware that opening MySQL for remote access may increase security risks, so configure it carefully and restrict access permissions.

bannerAds