"No such file or directory" error reported when connecting PHP to MySQL in Mac

Source: Internet
Author: User

First, let's give a brief introduction.

[NOTE 1] installation path of MYSQL in MAC:/usr/local/mysql-5.5.28-osx10.6-x86

The database data files are stored in the data folder of the directory;

The command file is in the bin folder.

[NOTE 2] how to open mysql command line via Terminal:/usr/local/mysql-5.5.28-osx10.6-x86/bin/mysql

Next, let's talk about the solution to the error when connecting to the MYSQL database.

1. First, it is determined that the problem is mysql_connect () and mysql_pconnect (). The fault is that the function returns NULL, while mysql_error () returns "No such file or directory"

2. On the phpinfo page, locate mysql. default_socket, mysqli. default_socket, and pdo_mysql.default_socket.

3. Start mysql (see description 2), execute the command STATUS, and write down the UNIX socket Value

4. If the values of 2 and 3 are different, open php. ini (you can find php. ini location. The default value is/private/etc/php. ini), change the value of the three configuration items mentioned in 2 to the value of 3.

(Note: There are three changes: mysql. default_socket, mysqli. default_socket, and pdo_mysql.default_socket)

5. Restart apache

OK. The error is excluded here.

Related Article

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.