最近準(zhǔn)備學(xué)習(xí)web項(xiàng)目需要用到數(shù)據(jù)庫刨晴,正好之前用公司的電腦裝過MySQL稠炬,試了一下發(fā)現(xiàn)本機(jī)用localhost 能連接陶缺,但是其他機(jī)器用IP卻連接不上点额,在網(wǎng)上看了一下解決方案入下:
第一步:先用其他電腦在命令行ping本機(jī)舔株,看能否ping通
C:\Windows\system32>ping 10.177.15.170
正在 Ping 10.177.15.170 具有 32 字節(jié)的數(shù)據(jù):
來自 10.177.15.170 的回復(fù): 字節(jié)=32 時(shí)間<1ms TTL=128
來自 10.177.15.170 的回復(fù): 字節(jié)=32 時(shí)間<1ms TTL=128
來自 10.177.15.170 的回復(fù): 字節(jié)=32 時(shí)間<1ms TTL=128
來自 10.177.15.170 的回復(fù): 字節(jié)=32 時(shí)間<1ms TTL=128
10.177.15.170 的 Ping 統(tǒng)計(jì)信息:
數(shù)據(jù)包: 已發(fā)送 = 4,已接收 = 4还棱,丟失 = 0 (0% 丟失)载慈,
往返行程的估計(jì)時(shí)間(以毫秒為單位):
最短 = 0ms,最長 = 0ms珍手,平均 = 0ms
如上則說明沒有問題
第二步:開放mysql的訪問
- 打開MySQL 命令行
- 輸入密碼在Enter password:
******
(自己的密碼) - 打開 mysql 數(shù)據(jù)庫:
use mysql
(因?yàn)镸ySQL的權(quán)限存在這個(gè)里面) - 將user='root'的用戶訪問權(quán)限為all:
update user set host='%' where user='root';
- 讓賦予的權(quán)限立即生效:
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)
注意最后一步如果沒執(zhí)行可能會(huì)導(dǎo)致修改后成功但還是訪問不了