There was an error when connecting to the MySQL database with thinkphp: sqlstate[hy000] [2002] No such file or directory
This is because PDO cannot connect to the database due to the Mysql.sock (or mysqld.sock) file path not specified in the php.ini configuration file
Configure the following three items in the php.ini file
Mysql.default_socket =/tmp/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sock
Mysqli.default_socket =/tmp/mysql.sock
The database using the MYSQLD engine should be modified to the following settings
Mysql.default_socket =/tmp/mysqld.sock
pdo_mysql.default_socket=/tmp/mysqld.sock
Mysqli.default_socket =/tmp/mysqld.sock
If you do not know whether you are using Mysql.sock or mysqld.sock files, or do not know the location of the Mysql_socket file, open the Phpinfo () function Information page to locate the MySQL extension in the following PHP extension, and find the MySQL inside _socket the corresponding path value can be copied, or directly in the hard disk search using the command find/-name Mysql.sock
Remember to restart the service after you have finished modifying it!
PHP connection to MySQL database encountered 2002 error under Linux