php - MySQL 在没有套接字文件的情况下运行

标签 php mysql macos

我已经在我的 MacOSX 10.7.3 上安装了 MySQL。

看起来 MySQL 正在运行:

Radeks-MacBook-Pro:htdocs radeksimko$ mysql5
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.61 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

我需要能够从 PHP 访问 MySQL,所以我尝试运行示例文件:

<?php
mysql_connect( "localhost", "user", "pass" );

但我有这个:

Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /usr/htdocs/index.php on line 4

我会在 php.ini 中设置 mysql.default_socket,但我真的无法在任何地方找到套接字文件...

它应该放在哪里/我怎样才能找到它? 这什么也没找到:

Radeks-MacBook-Pro:~ radeksimko$ sudo find / -name mysql.sock 2>/dev/null

最佳答案

尝试将第一个参数从“localhost”替换为“127.0.0.1”。可能会有帮助,我真的不知道 OSX。

(mysql_connect() 使用 mysql C 库,据我所知,它接受两种格式:127.0.0.1 和 localhost - 但是当您使用 localhost 时,库使用套接字文件,IP 地址使用 TCP 套接字。)

关于php - MySQL 在没有套接字文件的情况下运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9477552/

相关文章:

php - 混合 PDO 和 MySQL 函数?

python - Django 连接 mysql 出错

mysql - 在mysql中将一行字段设为空

swift - 使用AVPlayer从MacOS Swift应用程序将音频定向到空中播放扬声器

php - 分隔多个查询行结果?

PHP 从 Linux 和 Windows 连接到 MSSQL

php - 代码重用 : Common Functions - Laravel

php - mysql_query 更新不工作虽然我没有收到任何 mysql 错误

macos - 如何抑制(或自定义)Mac 终端 shell 提示

c++ - std::string::empty 的 undefined symbol 错误; Mac OS High Sierra 上的 c++ 标准方法链接错误