- The firewall needs to open port 3306
sudo ufw allow 3306
Or turn off the firewall:
sudo ufw disable
-
mysql open connection
-
remember your password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '123456';
- Modify the configuration file
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
这个值是127.0.0.1的时候只监听本地连接,改成0.0.0.0可以监听所有连接,或者也可以改成仅允许指定ip连接都可以。下面那一行类似的ip,可以把整行注释。
- Log in to mysql and check the permissions:
select user, host from user;
When the host is localhost, only local use is allowed, and it can be used remotely by changing it to %:
update user set host='%' where user='root';
Since the configuration file has been modified, the mysql service needs to be restarted to make the configuration file take effect:
service mysql stop;
service mysql start;
Test connection: