本地Navicat for MySQL连接虚拟机上的mysql

荆轲刺秦王

本地:win10

虚拟机:CentOS 7

1.先在本地 ping 虚拟机 ip

2、检查虚拟机 mysql 的端口是否对外开放

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.16 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like '%port%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| innodb_support_xa        | ON    |
| large_files_support      | ON    |
| port                     | 3306  |
| report_host              |       |
| report_password          |       |
| report_port              | 3306  |
| report_user              |       |
| require_secure_transport | OFF   |
+--------------------------+-------+
8 rows in set (0.01 sec)

mysql> quit
Bye
[root@localhost ~]# 

3. cmd 下执行 telnet 172.16.241.128 3306

这个地方需要本地开启 Windows telnet 服务 通常来讲 这个地方有一个客户端 一个服务端 两个都开启就行了 我这边是只有一个 客户端 但是不影响我使用

3.开启虚拟机相关端口

插曲:

systemctl status firewalld.service    查看防火墙状态

systemctl start firewalld.service  开启防护墙

systemctl stopfirewalld.service  关闭防火墙

编辑防火墙文件打开相关端口,因为你想要本地 postman 能访问 所以也需要开启80端口 数据库连接需要 3306 端口

vim /etc/sysconfig/iptables

模仿 22 端口开放命令添加如图所示的一行即表示对外开放 80 和 3306 端口

4、远程连接虚拟机数据库访问

 端口都开启了,但还是连不上,看提示说明至少已经关联到mysql,不允许是因为权限不够

 原因:一般 mysql 是不允许除了本机用户以外的用户进行访问的,所以需要给特定ip的用户开放权限,通过这个用户去访问连接

创建用户并附有所有权限 注意 需要在 mysql 下执行 就是登录 mysql 之后 再 use mysql 之后 一行一行的执行

create user 'ecshop_std'@'%' identified by 'ecshop_std';
grant all on *.* to 'ecshop_std'@'%';
flush privileges;

结果如图:

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值