Can ' t connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock ' (2) solution ideas

Source: Internet
Author: User

First explain the role of the Mysql.sock file:

There are two ways to connect MySQL, the first is TCP/IP, the second is to use UNIX domain socketdirectly, which is more than TCP/IP block.


Mysql.sock is available when the Mysql-server and client are on the same server when the local connection is initiated, without having to define the-H parameter to specify the specific IP. The mysql.sock is generated every time MySQL server starts, and the configuration parameters are typically generated in the/tmp/directory with Mysql.sock. That is, specify Socket=/tmp/mysql.sock in the/etc/my.cnf file


So if there is an error 2002 (HY000): Can ' t connect to local MySQL server through socket '/tmp/mysql.sock '.

(1) First verify that the configuration parameters are correct, try restarting MySQL.

(2) If not successful, you can use

Find/-name Mysql.sock

Locate the file. is not the socket is misplaced in other places, refer to the link

(3) Whether it is a permission setting problem,

Chown-r Mysql:mysql/var/lib/mysql

Reference links

(4) or ... Other conditions


But look, the problem I'm having here is Error 2002 (HY000): Can ' t connect to local MySQL server through socket '/VAR/RUN/MYSQLD/MYSQLD.SOC K ' (2)

Investigation:

(1) Find/-name mysql.sock see Mysql.sock in the/tmp/path,/ETC/MY.CNF socket path is also/tmp/mysql.sock;

(2) with

Ps-ef |grep MySQL

Look, there seems to be no problem.

Root 806 1 0 March 05? 00:00:00/bin/sh/usr/local/mysql/bin/mysqld_safe--datadir=/usr/local/mysql/var--pid-file=/usr/local/mysql/var/ Linpeisong-pc.pid


MySQL 1233 806 0 March 05? 00:00:27/usr/local/mysql/bin/mysqld--basedir=/usr/local/mysql--datadir=/usr/local/mysql/var--plugin-dir=/usr/ Local/mysql/lib/plugin--user=mysql--log-error=/usr/local/mysql/var/linpeisong-pc.err--pid-file=/usr/local/ Mysql/var/linpeisong-pc.pid --socket=/tmp/mysql.sock--port=3306


But if we manually specify the--socket parameter,

MySQL--socket=/tmp/mysql.sock-uroot-ppassword

can be connected normally.


(3) Finally, refer to this article to find the Source: Reference link


Because MySQL will read the configuration file/etc/my.conf,/etc/mysql/my.conf,/usr/etc/my.con,~/.my.conf sequentially, the following will overwrite the previous. At this point in my/etc/mysql/my.conf file, the configured socket parameter is

Socket =/var/run/mysqld/mysqld.sock

There is a way to create a linked file resolution, such as

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

However, in this way you may encounter PHP and can not find mysql.sock problem.

So rename the/etc/mysql/my.cnf directly

Mv/etc/mysql/my.cnf/etc/mysql/my.cnf_backup

You can use the default/etc/my.cnf to connect properly.


This article is from the "Novice PS Welcome Exchange" Blog, please be sure to keep this source http://linpeisong.blog.51cto.com/9601554/1748198

Can ' t connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock ' (2) solution ideas

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.