不能通过mysql.sock连接MySQL问题的解决办法

不能通过mysql.sock连接MySQL问题的解决办法

这个问题主要提示是,不能通过'/tmp/mysql.sock'连到服务器,而php标准配置正是用过'/tmp/mysql.sock',但是一些mysql安装方法将mysql.sock放在/var/lib/mysql.sock或者其他的什么地方,你可以通过修改/etc/my.cnf文件来修正它,打开文件,可以看到如下的东东:

[mysqld]

socket=/var/lib/mysql.sock

改一下就好了,但也会引起其他的问题,如mysql程序连不上了,再加一点:

[mysql]

socket=/tmp/mysql.sock

或者还可以通过修改php.ini中的配置来使php用其他的mysql.sock来连,这个大家自己去找找

或者用这样的方法:

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

还有:

phpmyadmin的说明书有说

Theerrormessage"Warning:MySQLConnectionFailed:Can'tconnecttolocalMySQLserverthroughsocket'/tmp/mysql.sock'(111)..."isdisplayed.WhatcanIdo?

ForRedHatusers,HaraldLegnersuggeststhisonthemailinglist:

OnmyRedHat-Boxthesocketofmysqlis/var/lib/mysql/mysql.sock.Inyourphp.iniyouwillfindaline

mysql.default_socket=/tmp/mysql.sock

changeitto

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

Thenrestartapacheanditwillwork.

HereisafixsuggestedbyBradUmmerinthephpwizardforum:

First,youneedtodeterminewhatsocketisbeingusedbyMySQL.

Todothis,telnettoyourserverandgototheMySQLbindirectory.Inthisdirectorythereshouldbeafilenamedmysqladmin.Type./mysqladminvariables,andthisshouldgiveyouabunchofinfoaboutyourMySQLserver,includingthesocket(/tmp/mysql.sock,forexample).

Then,youneedtotellPHPtousethissocket.

AssumingyouareusingPHP3.0.10orbetter,youcanspecifythesockettousewhenyouopentheconnection.TodothisinphpMyAdmin,youneedtocompletethesocketinformationintheconfig.inc.php3.

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