Warning:mysql_connect (): No such file or directory solution summary (OS: MAC)

Source: Internet
Author: User
Tags chmod mysql in phpinfo

Description

This article main content reference: the Mac under PHP connection MySQL error "No such file or directory" solution, and carry on the personal supplement

1. Operating environment: Mac OS X 10.11.4 (Mac already comes with Apache, PHP)

2. Related folders:

/ETC/APACHE2/# #Apache Configuration folder

/library/webserver/documents/# #Apache Default site

/USR/LOCAL/MYSQL-5.7.11-OSX10.9-X86_64 # #mysql安装路径

/private/php.ini.default # #php的配置文件: as configured Mysql.sock

>> cause of the problem:

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

A socket (appearing as a zero length file) As/tmp/mysql.sock Or/var/mysql/mysql.sock but 1 or more apps are Looking in the other location for it.

The great God explained: PHP in MySQL socket, the default configuration has a problem. So now just modify the PHP configuration file, configure the correct MySQL socket path is available.

>> Solutions:

1. Get current Mysql.default_socket, Mysqli.default_socket, pdo_mysql.default_socket configuration information

Create a PHP file that shows Phpinfo ():

<?phpecho phpinfo ();

Open with Browser:

On this page, locate Mysql.default_socket, Mysqli.default_socket, pdo_mysql.default_socket information:

2. Get the MAC MySQL socket path

Enter MySQL via console, input command: STATUS, find UNIX socket value

? /mysql-u root-pEnter Password:welcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is 8Server version:5.7.11 mysql Community Server (GPL) Copyright (c), Oracle and /or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. 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 wrapperconnection id:8current Database : Current User:[email protected]ssl:not in usecurrent pager:lessusing outfile: ' Using delimiter:; Server version:5.7.11 MySQL Community Server (GPL) Protocol version:10connection:localhost via UNIX socketserver  Characterset:utf8db characterset:utf8client Characterset:utf8conn. Characterset:utf8UNIX Socket:/tmp/mysql.sockUptime:8 days hours 1 min secthreads:2 questions:21 Slow queries:0 opens:114 Flush tables:1 Open tables:0 Queries per second avg:0.000--------------

3. At this time, you compare Mysql.default_socket, Mysqli.default_socket, Pdo_mysql.default_socket and through MySQL UNIX socket discovery is not the same, this is Mysql_c Onnect (); Reason for warning: PHP configuration MySQL has a problem.

4. Reconfigure PHP to open php.ini (the default location is:/private/etc/php.ini)

 

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

After modifying Mysql.default_socket, Mysqli.default_socket, Pdo_mysql.default_socket, the value is: /tmp/mysql.sock

(revised three places, respectively: Mysql.default_socket, Mysqli.default_socket, Pdo_mysql.default_socket)

Attention:

If the file opened with vim php.ini is empty (that is, when I do this), it means that there is no php.ini this file

This time, you browse/etc/folder, there will be Php.ini.default files, copy php.ini.default renamed to PHP.ini, and then use VIM to modify the contents of the file

CD/PRIVATE/ETC/CP php.ini.default php.ini      # #复制 Php.ini.default, and rename chmod +rwx php.ini              

5, restart Apache

sudo apachectl restart            # #重启 Apache

Warning:mysql_connect (): No such file or directory solution summary (OS: MAC)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.