Php cannot connect to mysql, But mysql command line operations are normal _ MySQL

Source: Internet
Author: User
Tags php website
A solution for php to connect to mysql but the mysql command line operation is normal failure: the php website fails to connect to mysql, but the command line can be used to log on and operate normally through the mysql command.
Solution:
1. log on to mysql under the command line and execute the following command:
Show variables like 'socket ';
After the command is executed, the Echo is similar to the following:

"Variable_name" "Value"
"Socket" "/home/mysql/data/mysql. sock"
2. edit php. ini, find mysql. default_socket configuration item. the default value is generally null (use the sock path set when you edit Mysql). add this item to "/home/mysql/data/mysql" in the preceding echo. sock ":

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL ULTS ults.
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.