php - PHP如何使用localhost用户和特定绑定(bind)地址连接到mysql

标签 php mysql

我的 Apache 和 mysql 服务器安装在同一台 linux 服务器上。 在我的 mysql 配置文件 /etc/mysql/my.cnf 中,我有这一行:

bind-address = 192.168.0.12

在我的 mysql 数据库中,我有一个用户 db_user 只能从 localhost 连接

User     Server      Password   Global privileges  "Grant"
db_user  localhost   Yes        USAGE              No

我不明白的是:如果 mysql 配置为仅绑定(bind) 192.168.0.12,php 如何连接到带有 db_user 和 localhost 域的 mysql 表?

我检查了主机文件,本地主机发送到 127.0.0.1 而不是 192.168.0.12。

另外,服务器上的这个命令有效:

mysql -udb_user -p"password" thedatabase

最佳答案

如果您指定localhost 作为要连接的主机,MySQL will use a socket ,而不是 TCP 连接。

关于php - PHP如何使用localhost用户和特定绑定(bind)地址连接到mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13066138/

相关文章:

PHP在字符串中最后一次出现字符后删除字符

php - 无法在 Laravel Dusk 中截图

php - PHP 可以在计时器到期后提交 HTML 表单吗?

php - MySQL 准备语句失败

MySQL:如何加速这个查询(包括子查询)?

php - PHP-无法打开流:没有这样的文件或目录

php - 使用PHP将多选表单中的数据存储到MYSQL

php - 如何获取 Magento 客户 ID

c# - 我收到此错误消息 : Access denied for user (Using password YES)

c# - 从 MySql 数据库读取平均值。 C# ASP.NET