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