Mac PHP connection mysql error "No such file or directory" solution

Source: Internet
Author: User
Tags phpinfo mysql command line

Let's start with a brief introduction.

[ Note 1] Installation path for MySQL under Mac:

/usr/local/mysql-5.1.63-osx10.6-x86_64

The data file of the database is in the folder of the directory;

The command file is in the Bin folder.

[ Note 2] The method of opening the MySQL command line via terminal:

/usr/local/mysql-5.1.63-osx10.6-x86_64

Okay, here's the solution to the wrong answer to the MySQL database.

1, first determine the problem is mysql_connect () and Mysql_pconnect (), the fault phenomenon is that the function returns NULL, and Mysql_error () returns "No such file or directory"

2, write a phpinfo page, find Mysql.default_socket, Mysqli.default_socket, Pdo_mysql.default_socket

3, start MySQL (see note 2), execute command STATUS; Note the value of the UNIX socket

4, if the values of 2 and 3 are different, open php.ini (you can find the location of php.ini from the Phpinfo page, which is/private/etc/php.ini by default), and change the value of the three configuration items mentioned in 2 to a value of 3.

(Note that the three places were modified: Mysql.default_socket, Mysqli.default_socket, Pdo_mysql.default_socket)

5, restart Apache

Mac PHP connection mysql error "No such file or directory" solution

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.