[MYSQL] DataGrip failed to connect to linux local mysql: Connection refused

  1. The firewall needs to open port 3306
sudo ufw allow 3306 

Or turn off the firewall:

sudo ufw disable
  1. mysql open connection

  2. remember your password

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '123456';
  1. Modify the configuration file
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

insert image description here

这个值是127.0.0.1的时候只监听本地连接,改成0.0.0.0可以监听所有连接,或者也可以改成仅允许指定ip连接都可以。下面那一行类似的ip,可以把整行注释。
  1. Log in to mysql and check the permissions:
select user, host from user;

insert image description here
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:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_43717839/article/details/132085165