mysql本地3306通过nginx映射到外网

mysql本地3306通过nginx映射到外网

  • 安装nginx, 版本大于1.19x
    • yum install nginx
  • 安装stream-module模块
    • 查看yum源,查找有没有 nginx-mod-stream.x86_64
      • yum list | grep nginx
  • 安装stream, 安装后就可以使用stream这个功能

    • yum install -y nginx-mod-stream.x86_64

nginx配置

  • 配置stream
    • 新建一个stream配置文件
      touch mysql.stream
    • 编写配置文件,我的配置文件如下
    •   upstream mysql_backend {
                server 172.16.0.3:3306; # 内网ip和3306端口
                # 可以根据需要添加更多的后端 MySQL 服务器
        }
        server {
                listen 3306; # 监听 MySQL 默认端口,也可以根据实际需要修改端口
                proxy_pass mysql_backend;
        }
      
      
  • 检查并重载nginx配置
    • nginx -t
    • nginx -s reload
  • 将MySQL服务器的默认身份验证插件从 caching_sha2_password 更改为 mysql_native_password。
    • mysql -uroot -p
    • ALTER USER 'root'@'%' IDENTIFIED WITH 'mysql_native_password' BY '你的密码';
    • FLUSH PRIVILEGES;
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值