Warning: mysql_connect(): No such file or directory 解决方案总结(操作系统: Mac)

说明:

 本文主要内容参考: Mac下PHP连接MySQL报错"No such file or directory"的解决办法, 并进行个人补充

  1. 运行环境: Mac OS X 10.11.4 (Mac 已经自带 Apache, PHP)

  2. 相关文件夹:

     /etc/apache2/     ##Apache 配置文件夹

     /Library/WebServer/Documents/    ##Apache 默认站点

     /usr/local/mysql-5.7.11-osx10.9-x86_64      ##mysql安装路径

    /private/php.ini.default      ##php的配置文件: 如配置 mysql.sock

>>问题原因:

For some reason mysql on OS X gets the locations of the required socket file a bit wrong, but thankfully the solution is as simple as setting up a symbolic link.

You may have a socket (appearing as a zero length file) as /tmp/mysql.sock or /var/mysql/mysql.sock but 1 or more apps is looking in the other location for it.

大神解释说: PHP 在 MySQL socket 方面, 默认的配置有问题. 那么现在只要修改 PHP 的配置文件, 配置正确的 MySQL socket 路径就可以了.

>>解决方案:

1. 获取当前 mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 配置信息

建立一个 PHP 文件, 显示 phpinfo():

<?php
echo phpinfo();

用浏览器打开:

在此页面,找到mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket信息:

2. 获取 Mac MySQL socket 路径

通过控制台进入 MySQL, 输入命令: STATUS, 查找 UNIX socket 值

?  / mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.11 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> STATUS
--------------
mysql  Ver 14.14 Distrib 5.7.11, for osx10.9 (x86_64) using  EditLine wrapper

Connection id:		8
Current database:
Current user:		[email protected]
SSL:			Not in use
Current pager:		less
Using outfile:		‘‘
Using delimiter:	;
Server version:		5.7.11 MySQL Community Server (GPL)
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8
Db     characterset:	utf8
Client characterset:	utf8
Conn.  characterset:	utf8
UNIX socket:		/tmp/mysql.sock
Uptime:			8 days 15 hours 1 min 17 sec

Threads: 2  Questions: 21  Slow queries: 0  Opens: 114  Flush tables: 1  Open tables: 0  Queries per second avg: 0.000
--------------

3. 这时候, 你对比 mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 和 通过 MySQL UNIX socket 发现不一样, 这就是 mysql_connect(); 警告的原因: PHP 配置 mysql 有问题.

 4. 重新配置 PHP, 打开php.ini(默认位置是: /private/etc/php.ini )

 

cd /private/etc/
chmod +rwx php.ini             ##修改文件权限
vim php.ini

之后修改mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 的值为: /tmp/mysql.sock

(一共修改三处,分别为:mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket)

注意:

若用 vim php.ini 打开的文件为空(我操作的时候, 就是这样), 说明没有 php.ini 这个文件

这个时候, 你浏览 /etc/ 文件夹下, 会有 php.ini.default 文件, 复制 php.ini.default 重命名为 php.ini , 再用 vim 修改文件内容

cd /private/etc/
cp php.ini.default php.ini      ##复制 php.ini.default, 并且重命名
chmod +rwx php.ini              ##修改文件权限
vim php.ini 

5,重启apache

sudo apachectl restart            ##重启 apache
时间: 2024-10-09 05:14:00

Warning: mysql_connect(): No such file or directory 解决方案总结(操作系统: Mac)的相关文章

解决MAC下PHP连接MYSQL错误Warning: mysql_connect(): No such file or directory in conn.php

今天在mac上用php去连接mysql数据库,出现了 mac PHP Warning:  mysql_connect(): [2002] No such file... 详细例如以下所看到的: DirkMacBook:vote Dirk$ phpunit MyTest.php  Warning: mysql_connect(): No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/myvote/vote/conn.

fatal error: openssl/sha.h: No such file or directory 解决方案

出现这个或者fatal error: openssl/名单.h: No such file or directory.都是没有安装libssl-dev- libssl-dev包含libraries, header files and manpages,他是openssl的一部分,而openssl对ssl进行了实现- 解决方案: 使用sudo apt-get install libssl-dev来安装libssl-dev即可

mysql_connect()“No such file or directory”错误排除

在部署LogAnalyzer时碰到一个mysql_connect()的错误,其实就是php抛出的错误! mysql_connect()函数:http://www.w3school.com.cn/php/func_mysql_connect.asp 主机环境:PHP5.6.1,Nginx1.4.7,Mysql5.5.40 此时的情况是,查询日志时间就会抛出这个错误,而其他模块,比如添加删除用户等,没有受影响, 执行SQL语句select DeviceReportedTime,FromHost,Me

win8/win7中使用Git Extensions PuTTy模式提交时 git-credential-winstore.exe&quot;: No such file or directory 错误解决方案

参考:http://www.cnblogs.com/hlizard/p/3627792.html 报错类似以下错误 \"F:/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" get: "F:/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe": No such file or directory 解决方案

libuuid.so: cannot open shared object file: No such file or directory

在玩ngx-lua时候有个 resty-uuid 需要引用 libuuid.so 动态库 打印log提示信息是这样的: libuuid.so: cannot open shared object file: No such file or directory 解决方案: [[email protected] ~]#yum install libuuid libuuid-devel [[email protected] ~]#ln -s /lib64/libuuid.so.1.3.0 /usr/l

JDK1.3安装出现/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory Done.

今天是出道以来第一次安装JDK1.3,大学的时候接触的也已是JDK1.4,而且是在Red Hat Enterprise Linux Server release 6.6上,安装JDK1.3是由于软件组一个项目使用的一个老版本的WebLogic的原因,由于各种原因一直没有升级. 在安装过程中遇到了 /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory错误. ./j2sdk-1_3_1_20-linux-i586.bin

# Creating Server TCP listening socket *:6379: bind: No such file or directory

刚装完redis就报错: # Creating Server TCP listening socket *:6379: bind: No such file or directory 解决方案如下: 1. redis-cli.exe2. shutdown3. exit4. redis-server.exe 原文地址:https://www.cnblogs.com/AlbertSmith/p/12568375.html

mac 连接mysql提示 Warning: mysqli::real_connect(): (HY000/2002): No such file or directory

mac 连接mysql的时候提示 Warning: mysqli::real_connect(): (HY000/2002): No such file or directory [说明1]MAC下MYSQL的安装路径:/usr/local/mysql-5.5.28-osx10.6-x86 数据库的数据文件在该目录的data文件夹中: 命令文件在bin文件夹中. [说明2]通过终端打开MYSQL命令行的方法:/usr/local/mysql-5.5.28-osx10.6-x86/bin/mysq

日志大量警告warning: unable to look up public/pickup: No such file or directory!

日志服务器大量警告: warning: unable to look up public/pickup: No such file or directory 报错原因: 与Debian Linux VPS 6,你可能得到Sendmail MTA违约.如果你已经安装和配置后缀这可能导致错误.如果您执行"echo|mail your.com"在本地配置(your.com)你会看到下面的错误出现:postdrop:warning: unable to look up public/picku