The solution to the MySQL problem cannot be connected via Mysql.sock

Source: Internet
Author: User

The main clue to this problem is that you can't connect to the server through '/tmp/mysql.sock ', and PHP standard configuration is using '/tmp/mysql.sock ', but some MySQL installation method will mysql.sock in/var/lib/ Mysql.sock or any other place, you can modify the/etc/my.cnf file to correct it, open the file, you can see the following dongdong:

[Mysqld]

Socket=/var/lib/mysql.sock

The change is good, but also can cause other problems, such as MySQL program can't even, add a little:

[MySQL]

Socket=/tmp/mysql.sock

Or you can modify the configuration in the php.ini to make PHP use the other mysql.sock to connect, this everyone to find

Or in this way:

Ln-s/var/lib/mysql/mysql.sock/tmp/mysql.sock

And also:

phpMyAdmin's manual says

The error message "Warning:mysql Connection Failed:can ' t connect to local MySQL server through socket '/tmp/mysql.sock ' (a) ... "is displayed. What can I do?

For RedHat users, Harald Legner suggests the mailing list:

On my redhat-box the socket of MySQL Is/var/lib/mysql/mysql.sock. In your php.ini your'll find a line

Mysql.default_socket =/tmp/mysql.sock

Change it to

Mysql.default_socket =/var/lib/mysql/mysql.sock

Then restart Apache and it'll work.

Here are a fix suggested by Brad Ummer in the Phpwizard forum:

Need to determine what the socket is being used by MySQL.

To doing this, telnet to your server and go to the MySQL bin directory. In this directory there should is a file named Mysqladmin. Type./mysqladmin variables, and this should give you a bunch of info about your MySQL server, including the socket (/tmp/ Mysql.sock, for example).

Then, you are need to tell PHP to the use this socket.

Assuming you are a using PHP 3.0.10 or better, you can specify the "socket to" when you open the connection. To does this in phpMyAdmin, you need to complete the socket information in the CONFIG.INC.PHP3.

For example: $cfg [' Servers '] [$i] [' socket '] = '/tmp/mysql.sock ';

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.