Can 'tconnecttolocalmysqlserverthroughsocket

Source: Internet
Author: User
Problem description: php cannot connect to the local database when connecting to the local database through localhost. Analysis: php connects to the local database through localhost through socket connection. Therefore, you must find the socket file corresponding to mysql. Php connects to mysql through mysql, mysqli, and pdo_mysql in localhost mode and reads the php. ini file.

Problem description: php cannot connect to the local database when connecting to the local database through localhost. Analysis: php connects to the local database through localhost through socket connection. Therefore, you must find the socket file corresponding to mysql. Php connects to mysql through mysql, mysqli, and pdo_mysql in localhost mode and reads the php. ini file.

Problem description

Php cannot connect to the local database through localhost

Problem Analysis

Php uses localhost to connect to the local database through socket. Therefore, you must find the socket file corresponding to mysql. Php connects to mysql through mysql, mysqli, and pdo_mysql in localhost mode and reads the default-socket settings in the php. ini file. My php and mysql are both compiled and installed. At that time, the mysql socket file location was not specified. mysql generated the file location and the default value in php (/tmp/mysql. sock.

Solution

1. connect through an IP address. For example, mysql_connect ('192. 0.0.1 ', 'root ',");

2. Specify the mysql socket file address.

First, find the mysql socket file address.

Sudo find/-name mysqld. sock or

Echo "show variables" | mysql-uroot-ppassword | grep "socket"

The socket file address of mysql is returned as follows:
/Run/mysqld. sock

Modify the settings in three places in the php. ini file.

Mysql. default_socket, mysqli. default_socket, pdo_mysql.default_socket

3. Modify socket in my. cnf? ? ? ? ? =/Var/run/mysqld. sock (this parameter is available in several places and is not recommended for modification)

4. Soft link

Ln-s? /Var/run/mysqld. sock? /Tmp/mysql ?. Sock

Undoubtedly, the first method is the simplest.

Original article address: Can't connect to local MySQL server through socket, thanks to the original author for sharing.

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.