当前位置: 首页 > news >正文

mysql连接不上问题解决

公司新搭内网测试环境,mysql远程登录问题解决
远程登录:
1 修改host,

mysql> select user,host,plugin from user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| root             | %         | auth_socket           |
| debian-sys-maint | localhost | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
mysql> alter user 'root'@'%' identified by '123456';
//注意这里如果用update的话 可能会报错:
mysql> update user set authentication_string=password("123456"),plugin='mysql_native_password' where user='root';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '("123456"),plugin='mysql_native_password' where user='root'' at line 1

2 配置文件 bind-address = 0.0.0.0 设置这里为你的ip或者全部ip 0.0.0.0代表所有

vim my.cnf

3 防火墙

ufw allow 3306/tcp;
ufw status;
root@base-ubuntu20: ufw allow 3306/tcp
规则已添加
规则已添加 (v6)
root@base-ubuntu20: ufw status;
状态: 激活至                          动作          来自
-                          --          --
443                        ALLOW       Anywhere                  
80/tcp                     ALLOW       Anywhere                  
22/tcp                     ALLOW       Anywhere                  
3306/tcp                   ALLOW       Anywhere                  
443 (v6)                   ALLOW       Anywhere (v6)             
80/tcp (v6)                ALLOW       Anywhere (v6)             
22/tcp (v6)                ALLOW       Anywhere (v6)             
3306/tcp (v6)              ALLOW       Anywhere (v6)  

4 加密方式(plugin=mysql_native_password),

mysql> update user set plugin='mysql_native_password' where user='root'-> ;
Query OK, 1 row affected (0.71 sec)
Rows matched: 1  Changed: 1  Warnings: 0mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

5 设置登陆密码(authentication_string)


select host,user,authentication_string,plugin from user;	update user set plugin='mysql_native_password' where user='root';alter user 'root'@'%' identified by '123456';

以上每一次做完 都flush一次。

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

最后重启mysql 服务 service mysql restart
参考:

https://blog.csdn.net/appleyuchi/article/details/113196484
https://zhuanlan.zhihu.com/p/391311322
https://blog.csdn.net/weixin_51563198/article/details/121529081

或者 如果不想用root。 自己新建一个账号:

create user 'tom'@'%' identified by 'tom123';grant all privileges on *.* to 'tom'@'%' WITH GRANT OPTION;
flush privileges;

all privileges : 所有权限
*.* : 所有的数据库中的所有的表
WITH GRANT OPTION :权限给分享给自己创建的用户

http://www.lryc.cn/news/42604.html

相关文章:

  • 利用nginx实现动静分离的负载均衡集群实战
  • 与chatGPT神聊,引领你深入浅出系统调用
  • 自学大数据第十天~Hbase
  • vue更高效的工具-vite
  • HFish蜜罐的介绍和简单测试(一)
  • 2023面试题汇总二
  • C# 支付宝接口在线收款退款
  • python例程:《企业编码生成系统》程序
  • 基于EB工具的TC3xx_MCAL配置开发04_ADC模块软件触发Demo配置
  • 内存操作函数
  • 免费搭建个人博客
  • 【Vue全家桶】详解Vue Router(一)
  • 9大 HIVE SQL 最频繁被问到的面试题
  • 学大数据算跟风吗?
  • [C#]关于ListBox的坑
  • Apache POI 入门·第一话
  • 8个python自动化脚本提高打工人幸福感~比心~
  • 【嵌入式烧录/刷写文件】-1-详解Motorola S-record(S19/SREC/mot/SX)格式文件
  • 图形视图界面 图形效果
  • ElementUI学习笔记
  • 安装KVM并创建虚拟机及基本使用
  • 一种LCD屏闪问题的调试
  • Java程序运行在Docker等容器环境有哪些新问题?
  • C语言面试最常问的三个关键字
  • 【Linux】-初识Linux
  • 精选7个 Python 学习资源库,助你成为优秀的开发者
  • 【大数据处理与可视化】三 、Pandas库的运用
  • FPGA解码SDI视频任意尺寸缩放拼接输出 提供工程源码和技术支持
  • 线索二叉树结构
  • 6.网络爬虫——BeautifulSoup详讲与实战