Navicat 连接不上虚拟机centos的mysql

Navicat 连接不上虚拟机centos的mysql

[root@bogon ~]# service mysql start

Redirecting to /bin/systemctl start mysql.service

[root@bogon ~]# 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.6.45 MySQL Community Server (GPL)


Copyright (c) 2000, 2019, 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> grant all privileges on *.* to root@"%" identified by "new_mysql";

Query OK, 0 rows affected (0.00 sec)


mysql> grant all privileges on *.* to root@"bogon" identified by "new_mysql";

Query OK, 0 rows affected (0.00 sec)


mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)


mysql> quit

Bye

[root@bogon ~]# iptables -F

[root@bogon ~]# systemctl stop firewalld

[root@bogon ~]# systemctl disable firewalld

[root@bogon ~]# ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.131.131  netmask 255.255.255.0  broadcast 192.168.131.255

        inet6 fe80::20c:29ff:fe4e:4a5b  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:4e:4a:5b  txqueuelen 1000  (Ethernet)

        RX packets 284  bytes 28044 (27.3 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 395  bytes 31836 (31.0 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 1000  (Local Loopback)

        RX packets 0  bytes 0 (0.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 0  bytes 0 (0.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255

        ether 52:54:00:d0:d8:4b  txqueuelen 1000  (Ethernet)

        RX packets 0  bytes 0 (0.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 0  bytes 0 (0.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


[root@bogon ~]# ping www.baidu.com

PING www.a.shifen.com (163.177.151.109) 56(84) bytes of data.

64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=1 ttl=128 time=38.4 ms

64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=2 ttl=128 time=34.7 ms

64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=3 ttl=128 time=33.1 ms

^A64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=4 ttl=128 time=33.2 ms

64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=5 ttl=128 time=30.1 ms

64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=6 ttl=128 time=32.9 ms

64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=7 ttl=128 time=47.0 ms

http://img1.sycdn.imooc.com//climg/5d3d2999000169bb05660668.jpg

虚拟机网络是通的

Navicat的ip地址也没错

root的密码也没错

为什么就是连接不上呢?

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
慕之熠_灿烈 2019-07-28 15:14:58

同学,你好。

(1)首先在本地使用ping命令,远程访问虚拟机的ip地址,查看是否相通

(2)若(1)中本地与虚拟机网络相通,则登录虚拟机中的mysql数据库,选择mysq数据库,查看user=root 信息(如下图):

http://img1.sycdn.imooc.com//climg/5d3d49e30001253703760212.jpg

可以看到,root的用户只允许本地访问,现在需要改成所有或者指定IP,(注意:在完成该步骤后记得执行flush privileges(如下图))

http://img1.sycdn.imooc.com//climg/5d3d4a120001d15607930149.jpg

(3)若(1)中本地与虚拟机网络不相通,请严格依据个人的硬件配置和环境参考资料使得二者可以网络互通

如果我解决了您的问题,请采纳!祝~学习愉快~

  • 我刚才试了一下原来是我使用的是静态ip地址,改成动态ip地址就好了,我还有一个疑问就是为什么一定要用动态ip地址?
    2019-07-28 15:18:20
  • 这个使用动态IP的主要原因就是提升连接效率和安全性的监督考虑,具体表现在节约带宽和隐藏真实IP两个方面。
    2019-07-28 19:14:31
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师