Why can't php-fpm connect to mysql?

Source: Internet
Author: User
Tags mysql functions php database
The following error message is displayed: Warning: mysqli_connect (): Response. Headers: 50625 Library: 50541insrvpmatest. phponline8Warning: mysqli_connect () :( HY0002002): Ca... the following error message is displayed:
Warning: mysqli_connect (): Headers and client library minor version mismatch. Headers: 50625 Library: 50541 in/srv/pma/test. php on line 8

Warning: mysqli_connect (): (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql. sock '(2) in/srv/pma/test. php on line 8

I am in php. mysql. default_socket =/var/mysql. sock. I don't know why I couldn't find the socket in this file. I can use the command line to connect to mysql and set the password. What is the problem?

Reply content:

The following error message is displayed:
Warning: mysqli_connect (): Headers and client library minor version mismatch. Headers: 50625 Library: 50541 in/srv/pma/test. php on line 8

Warning: mysqli_connect (): (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql. sock '(2) in/srv/pma/test. php on line 8

I am in php. mysql. default_socket =/var/mysql. sock. I don't know why I couldn't find the socket in this file. I can use the command line to connect to mysql and set the password. What is the problem?

The host of your php database should use localhost. In this case, you will use the socket method to connect to the database.

The socket file path in the error message is inconsistent with that in your php. ini file.
Conjecture 1. You may have modified php. ini, but did not restart php-fpm.
Conjecture 2. php may exist in multiple paths on your machine. ini, but php-fpm does not load the php you modified. ini. you can write a page and use phpinfo to confirm your php. ini path.

In addition, please check the specified socket path of mysqld section in your mysql configuration file my. cnf.

Several configuration items about MySQL Socket in php. ini:
Mysql. default_socket corresponds to mysql Functions
Mysqli. default_socket corresponds to mysqli series Functions
Pdo_mysql.default_socket corresponds to pdo_mysql series Functions

We do not recommend that you use the MySQL connection information in php. ini. We recommend that you directly specify the socket or Port location in mysqli_connect:

$mysqli = mysqli_connect(    null, // $app['db_host'],     $app['db_username'],     $app['db_password'],     $app['db_name'],     null, // $app['db_port']    $app['db_socket']);

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.