PHP PDO connection Error connection failed:sqlstate[hy000] [2002]_php Tutorial

Source: Internet
Author: User

PHP PDO connection Error connection failed:sqlstate[hy000] [2002]


Let's look at the PHP pdo_mysql connection error Connection failed:sqlstate[hy000] [2002] No such file or directory problem resolution.

Error

Connection failed:sqlstate[hy000] [2002] No such file or directory

Environment Overview:

MacOS

XAMPP build the development environment Apache MySQL PHP

XAMPP has supported MySQL Oracle Test OK, and Phpinfo has shown support Pdo_mysql Pdo_pgsql Pdo_sqlite

Which MySQL I used is the brew package management installed into the machine, rather than the xampp comes with MySQL

PHP PDO connection Error Connection failed:sqlstate[hy000] [2002] No such file or directory

Started to think that the file could not be found because the URL rewrite caused, (because the switch from Nginx to Apache) Results Tracer found to be new PDO error

After searching for some data, the study found:

This is the Mysql.sock path specified in the php.ini configuration file that is not Pdo_mysql.default_socket

My Mysql.sock file is in/private/tmp/mysql.sock

So to set:

Pdo_mysql.default_socket=/private/tmp/mysql.sock

If you do not know where your mysql.sock can be searched (because of a compilation installation, it is not the same location as the package management tools like Yum, Apt-get, or brew)

sudo find/-name ' Mysql.sock '

Here is the official bug fix

1. Open up PHP.ini (mine was in/private/etc/)

2. Locate this Line:pdo_mysql.default_socket=/var/mysql/mysql.sock

3. Change the line To:pdo_mysql.default_socket=/tmp/mysql.sock

4. Restart Apache

1, I need to add here, if it is a new system or just play PHP comrade, in the Mac system php.ini file does not exist,

2, need in/private/etc/directory CP Php.ini.default

PHP.ini, and then make the change,

3, but if the use of XAMPP MySQL as a database, then you do not need to use the official Step2, directly write the following way can be.

Pdo_mysql.default_socket=/applications/xampp/xamppfiles/var/mysql/mysql.sock

Workaround Three

sudo vim/etc/php.ini

Set the following three original blank values to/tmp/mysql.sock

Mysql.default_socket =/tmp/mysql.sock

pdo_mysql.default_socket=/tmp/mysql.sock

Mysqli.default_socket =/tmp/mysql.sock

have been modified.

Use after modification is complete

Sudo/usr/sbin/apachectl restart

http://www.bkjia.com/PHPjc/926230.html www.bkjia.com true http://www.bkjia.com/PHPjc/926230.html techarticle PHP PDO connection error connection failed:sqlstate[hy000] [2002] below we look at the PHP pdo_mysql connection error connection failed:sqlstate[hy000] [ 2002] No such file or directory problem ...

  • 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.