主题: 配置 phpMyAdmin,服务器地址填 localhost 好呢,还是 IP 地址好?

这是最近发现的一个细节问题,也是许多朋友会碰到的问题:
配置 phpMyAdmin 时,服务器地址填 localhost 好呢,还是 IP 地址好?

根据 phpMyAdmin 官方 FAQ 2.6 章节的解释:

if your host is "localhost" MySQL (the commandline tool 'mysql' as well) always tries to use the socket connection for speeding up things. And that doesn't work in this configuration with port forwarding.
If you enter "127.0.0.1" as hostname, everything is right and MySQL uses the TCP connection.

也就是说,如果你使用 'localhost' 作为 MySQL 服务器地址,MySQL 客户端工具(例如 'mysql' 命令),以及 phpMyAdmin 都会默认使用 socket 来连接 MySQL 服务器,以获得更好的连接速度和性能。如果使用 IP 地址(例如 '127.0.0.1'),则会使用 TCP/IP 方式去连接 MySQL 服务器。

所以配置 phpMyAdmin 时,请根据实际情况选择使用 'localhost' 还是使用 '127.0.0.1'。

参考文档:

- phpMyAdmin FAQ 2.6:
http://www.phpmyadmin.net/documentation/#faq2_6