【MYSQL】DataGrip连接linux本地mysql失败:Connection refused

  1. 防火墙需要开放3306端口
bash 复制代码
sudo ufw allow 3306 

要么就把防火墙关了:

bash 复制代码
sudo ufw disable
  1. mysql开放连接

  2. 记住你的密码

bash 复制代码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '123456';
  1. 修改配置文件
bash 复制代码
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
复制代码
这个值是127.0.0.1的时候只监听本地连接,改成0.0.0.0可以监听所有连接,或者也可以改成仅允许指定ip连接都可以。下面那一行类似的ip,可以把整行注释。
  1. 登陆mysql,查看权限:
bash 复制代码
select user, host from user;

host处为localhost时只允许本地使用,改成%即可远程使用:

bash 复制代码
update user set host='%' where user='root';

由于修改了配置文件,所以需要重启mysql服务使配置文件生效:

bash 复制代码
service mysql stop;
service mysql start;

测试连接:

相关推荐
Android轮子哥3 分钟前
Android 12 SplashScreen 一种另类的适配方案
android·github
小鹏linux18 分钟前
【像素贪吃蛇小游戏】部署文档-linux篇
linux·运维·服务器
DD-WL33 分钟前
PKI&&数字证书相关概念
linux·网络协议
粤M温同学34 分钟前
Android OkHttp 下载限速方案实现
android·okhttp
邵伯正在输入36 分钟前
Mysql锁之插入意向锁
数据库·mysql
路溪非溪40 分钟前
Linux驱动中的红外遥控子系统
linux·arm开发·驱动开发
qq192572302741 分钟前
商品库存管理系统(MYSQL)
数据库·mysql
成都犀牛1 小时前
Ubuntu配置nginx
linux·nginx·ubuntu
qdprobot1 小时前
开源的在线串口调试助手支持macOS苹果电脑Windows系统Linux 浏览器webSerial
linux·运维·服务器·人工智能·mixly·小智ai·webserial
wdfk_prog1 小时前
[Linux]学习笔记系列 -- [fs]namespace
linux·笔记·学习