美文网首页
如何让局域网内其他电脑连接我们自己的本地mysql数据库

如何让局域网内其他电脑连接我们自己的本地mysql数据库

作者: 别动我名字呀 | 来源:发表于2019-04-29 14:48 被阅读0次

最近准备学习web项目需要用到数据库,正好之前用公司的电脑装过MySQL,试了一下发现本机用localhost 能连接,但是其他机器用IP却连接不上,在网上看了一下解决方案入下:

第一步:先用其他电脑在命令行ping本机,看能否ping通

C:\Windows\system32>ping 10.177.15.170


正在 Ping 10.177.15.170 具有 32 字节的数据:
来自 10.177.15.170 的回复: 字节=32 时间<1ms TTL=128
来自 10.177.15.170 的回复: 字节=32 时间<1ms TTL=128
来自 10.177.15.170 的回复: 字节=32 时间<1ms TTL=128
来自 10.177.15.170 的回复: 字节=32 时间<1ms TTL=128

10.177.15.170 的 Ping 统计信息:
   数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
   最短 = 0ms,最长 = 0ms,平均 = 0ms

如上则说明没有问题

第二步:开放mysql的访问

  • 打开MySQL 命令行
  • 输入密码在Enter password: ******(自己的密码)
  • 打开 mysql 数据库:use mysql(因为MySQL的权限存在这个里面)
  • 将user='root'的用户访问权限为all:update user set host='%' where user='root';
  • 让赋予的权限立即生效:flush privileges

完整流程入下:

Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.15 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> use mysql
Database changed

mysql> update user set host='%' where host= 'localhost';
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> select host,user from user;
+------+------------------+
| host | user             |
+------+------------------+
| %    | mysql.infoschema |
| %    | mysql.session    |
| %    | mysql.sys        |
| %    | root             |
+------+------------------+
4 rows in set (0.00 sec)


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

注意最后一步如果没执行可能会导致修改后成功但还是访问不了

相关文章

网友评论

      本文标题:如何让局域网内其他电脑连接我们自己的本地mysql数据库

      本文链接:https://www.haomeiwen.com/subject/umsynqtx.html