简体   繁体   English

PHP如何在同一台服务器上与MySQL通信

[英]How does PHP communicate with MySQL on the same server

Does anyone know how php requests data from mysql? 有谁知道php如何从mysql请求数据?

If I have mysql in the same machine as php, does it open a tcp connection to the localhost on port 3306 or does it have some other way of getting the data? 如果我在与php相同的机器上安装了mysql,它是否在端口3306上打开了与localhost的tcp连接,还是有其他方式获取数据?

Is it the same in linux and windows? 在linux和windows中它是一样的吗?

Thanks 谢谢

if available it uses a unix socket, otherwise localhost. 如果可用,它使用unix套接字,否则使用localhost。

Note that even if you specify localhost in the connection string it will try to use the faster "unix socket" if available 请注意, 即使您在连接字符串中指定了localhost ,它也会尝试使用速度更快的“unix socket”(如果可用)

通常PHP打开在/tmp/mysql.sock中找到的本地管道以连接到本地版本的服务器,除非您在连接字符串中使用IP地址。

PHP opens a connection to port 3306 is the server via TCP to allow data communication. PHP打开与端口3306的连接是服务器通过TCP来允许数据通信。 Hence, you can specify which port to connect to in mysql(i)_connect etc, and why, you need to have firewall rules for mysql. 因此,您可以在mysql(i)_connect等中指定要连接的端口,以及为什么需要为mysql配置防火墙规则。

It is the same in Windows as Linux 它在Windows中与Linux相同

So yes, TCP :) 所以是的,TCP :)

EDIT: Revision, In linux, php looks to connect to mysql via /tmp/mysql.sock the tmp directory needs to have correct permissions. 编辑:修订,在Linux中,php看起来通过/tmp/mysql.sock连接到mysql,tmp目录需要具有正确的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM