PHP is not connected to MySQL but MySQL command-line operation is normal solution _mysql

Source: Internet
Author: User
Failure Status: PHP Web Connection MySQL failed, but at the command line through the MySQL command to log in and normal operation.
Solution:
1, under the command line login MySQL, execute the following command:
Copy Code code as follows:
Show variables like ' socket ';

After execution, it will be similar to the following echo:
Copy Code code as follows:

"Variable_name" "Value"
"Socket" "/home/mysql/data/mysql.sock"

2, edit php.ini, find mysql.default_socket configuration items, the default is generally null value (use edit MySQL set sock path), add this value to the above echo in the "/home/mysql/data/mysql.sock":
Copy Code code as follows:

;  Default socket name for the local MySQL connects. If empty, uses the built-in
; MySQL defaults.
Mysql.default_socket =/home/mysql/data/mysql.sock

3, restart PHP.

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.