php mysql localhost,127.0.0.1和ip區(qū)別
一家之言:
localhost與127.0.0.1的區(qū)別
localhost與127.0.0.1的區(qū)別是什么?相信有人會說是本地ip,曾有人說,用127.0.0.1比localhost好,可以減少一次解析??磥磉@個入門問題還有人不清楚,其實這兩者是有區(qū)別的。
no1:
localhost也叫l(wèi)ocal ,正確的解釋是:本地服務(wù)器
127.0.0.1在windows等系統(tǒng)的正確解釋是:本機地址(本機服務(wù)器)
no2:
localhot(local)是不經(jīng)網(wǎng)卡傳輸!這點很重要,它不受網(wǎng)絡(luò)防火墻和網(wǎng)卡相關(guān)的的限制。
127.0.0.1是通過網(wǎng)卡傳輸,依賴網(wǎng)卡,并受到網(wǎng)絡(luò)防火墻和網(wǎng)卡相關(guān)的限制。
一般設(shè)置程序時本地服務(wù)用localhost是最好的,localhost不會解析成ip,也不會占用網(wǎng)卡、網(wǎng)絡(luò)資源。
有時候用localhost可以,但用127.0.0.1就不可以的情況就是在于此。猜想localhost訪問時,系統(tǒng)帶的本機當(dāng)前用戶的權(quán)限去訪問,而用ip的時候,等于本機是通過網(wǎng)絡(luò)再去訪問本機,可能涉及到網(wǎng)絡(luò)用戶的權(quán)限。
他家之言:
1. mysql -h 127.0.0.1 的時候,使用TCP/IP連接,
mysql server 認(rèn)為該連接來自于127.0.0.1或者是"localhost.localdomain"
2. mysql -h localhost 的時候,是不使用TCP/IP連接的,而使用Unix socket;
此時,mysql server則認(rèn)為該client是來自"localhost"
3. mysql權(quán)限管理中的"localhost"有特定含義:
—— MySQL手冊 5.6.4 ..... A Host value may be a hostname or an IP number, or 'localhost' to indicate the local host.
注意:雖然兩者連接方式有區(qū)別,但當(dāng)localhost 為默認(rèn)的127.0.0.1時,兩種連接方式使用的權(quán)限記錄都是以下的1.row的記錄(因為記錄在前,先被匹配)
*************************** 1. row ***************************
Host: localhost
User: root
......
*************************** 2. row ***************************
Host: 127.0.0.1
User: root
證明:
shell> mysql -h 127.0.0.1
mysql> status;
Current user: root@127.0.0.1
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.1.33-log Source distribution
Protocol version: 10
Connection: 127.0.0.1 via TCP/IP
shell> mysql -h locahost
mysql> status;
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.1.33-log Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket
shell> mysql -h XXXX(ip)
mysql> status;
Current user: root@ip
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.1.33-log Source distribution
Protocol version: 10
Connection: XXXX(ip) via TCP/IP
相關(guān)文章
關(guān)于mysql主備切換canal出現(xiàn)的問題解決
這篇文章主要給大家介紹了關(guān)于mysql主備切換canal出現(xiàn)的一些問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11Navicat Premium如何導(dǎo)入SQL文件的方法步驟
這篇文章主要介紹了Navicat Premium如何導(dǎo)入SQL文件的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03淺談mysql雙層not exists查詢執(zhí)行流程
本文主要介紹了淺談mysql雙層not?exists查詢執(zhí)行流程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06