mysql h 127.0.0.1_MySQL 连接时尽量使用 127.0.0.1 而不是 localhost
原因
Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as in your PHP configuration and leave the server field blank.
localhost 使用的 Linux socket,127.0.0.1 使用的是 tcp/ip
為什么我使用 localhost 一直沒出問題
因為你的本機中只有一個 mysql 進程, 如果你有一個 node1 運行在 3306, 有一個 node2 運行在 3307
mysql -u root -h localhost -P 3306
mysql -u root -h localhost -P 3307
都會連接到同一個 mysql 進程, 因為 localhost 使用 Linux socket, 所以 -P 字段直接被忽略了, 等價于
mysql -u root -h localhost
mysql -u root -h localhost
而 -h 默認是 localhost, 又等價于
mysql -u root
mysql -u root
為了避免這種情況(比如你在本地開發只有一個 mysql 進程,線上或者 qa 環境有多個 mysql 進程)最好的方式就是使用 IP
mysql -u root -h 127.0.0.1 -P 3307
總結
以上是生活随笔為你收集整理的mysql h 127.0.0.1_MySQL 连接时尽量使用 127.0.0.1 而不是 localhost的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 论那些叔叔奶奶,不知道怎么面对他们?[已
- 下一篇: 我爱你就像飞蛾扑向火是哪首歌啊?