PHP connection to MySQL database encountered 2002 error under Linux

Source: Internet
Author: User

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

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.