Set up a remote connection to MySQL

After installing a new Ubuntu on Alibaba Cloud, mysql is installed, but mysql can only be connected locally, not remotely. After looking up information online, the following modifications were made.

1. Change the ip address that mysql listens to

First, check whether the mysql listening IP and port are normal.

Use: netstat -anpt command

If the listening address is :::3306 or 0.0.0.0:3306, it means listening to all IP addresses, and the listening state is normal. If 127.0.0.0:3306 or no 3306 appears, you need to modify it in the mysql configuration file and restart mysql.

Enter the mysql configuration folder and modify mysqld.cnf (different versions of mysql configuration file paths may be different)


vi /etc/mysql/mysql.conf.d/mysqld.cnf

Comment out bind-address = 127.0.0.1


2. Set mysql user permissions for remote access

Log in to the mysql server locally,

use mysql;

SELECT user, host from mysql.user; View the permissions of the mysql user host used for remote access, % means that all machines are allowed to access. If the host is 127.0.0.1/localhost, then this user can only access locally, you need to change the host to %, you can use update user set host='%' where user='root';



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324678692&siteId=291194637