Can‘t connect to local MySQL server through socket

连接Mysql提示Can’t connect to local MySQL server through socket的解决方法

2013年9月6日 aiezu 发表评论 阅读评论

mysql,Mysqldump,Mysqladmin,php连接mysql服务常会提示下面错误:

ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/<span class=‘wp_keywordlink_affiliate‘><a href="http://www.aiezu.com/tag/mysql-2" title="查看 mysql 中的全部文章" target="_blank">mysql</a></span>/mysql.sock‘ (2)


1


ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)

这是由于修改mysql服务的了socket文件mysql.sock位置,而导致无法通过mysql socket文件连接到mysql服务引起的,具体解决办法如下:
1、查看mysql服务的socket文件位置:
mysql socket文件的位置是在/etc/my.cnf中设置的,cat /etc/my.cnf内容如下:

[mysqld] datadir=/storage/db/mysql socket=/storage/db/mysql/mysql.sock user=mysql


1

2

3

4


[mysqld]

datadir=/storage/db/mysql

socket=/storage/db/mysql/mysql.sock

user=mysql

其中socket等于的路径就是socket文件的位置,我们只要修改my.cnf文件,告诉mysql,mysqldump,mysqladmin mysql服务的socket位置在哪里就可以。

2、修改my.cnf文件:
在/etc/my.cnf文件中添加如下内容,并重启mysqls服务,即可解决mysql,mysqldump,mysqladmin的“Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘”问题:

[mysqld] datadir=/storage/db/mysql socket=/storage/db/mysql/mysql.sock [mysql] socket=/storage/db/mysql/mysql.sock [mysqldump] socket=/storage/db/mysql/mysql.sock [mysqladmin] socket=/storage/db/mysql/mysql.sock


1

2

3

4

5

6

7

8

9

10

11

12


[mysqld]

datadir=/storage/db/mysql

socket=/storage/db/mysql/mysql.sock

[mysql]

socket=/storage/db/mysql/mysql.sock

[mysqldump]

socket=/storage/db/mysql/mysql.sock

[mysqladmin]

socket=/storage/db/mysql/mysql.sock

时间: 2024-10-31 14:30:25

Can‘t connect to local MySQL server through socket的相关文章

解决mysql报错Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

启动mysql 报错: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 1.先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动.另外看看是不是权限问题. 2.确定你的mysql.sock是不是在那个位置,mysql -u 你的mysql用户名 -p -S /var/lib/mysql/

mysql连接报错 ERROR 2002 (HY000): Can&#39;t connect to local MySQL server through socket

安装完mysql连接报错: [[email protected] app]# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) [[email protected] app]# mysql -uroot -p Enter password:  ERROR 2002 (HY000): Can't connect to local M

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了 ps -A | grep -i mysql kill 列出来的进程 service mysql start 我的问题就解决了 ---------------------------------------------- Fedora8启动mysql 报错:ERROR 2002 (HY000): Can’t connect

MAC中Django中runserver提示Can&#39;t connect to local MySQL server through socket &#39;/tmp/mysql.sock错误

好像不止遇到一次,直接Google就可以了,在stackoverflow中就有答案,答案就是你没有开MySQL - -. stackoverflow链接见 http://stackoverflow.com/questions/16325607/cant-connect-to-local-mysql-server-through-socket-tmp-mysql-sock 开启MySQL的命令如下: mysql.server start MAC中Django中runserver提示Can't co

Can&#39;t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘ (2)解决思路

首先说明一下mysql.sock文件的作用: 连接mysql有两种方式,第一种是TCP/IP,第二种就是直接使用unix domain socket,它比TCP/IP块. mysql.sock是在mysql-server和client在同一服务器上时,发起本地连接时可用,而无需定义-h参数指定具体的IP.mysql.sock是随每次mysql server启动时生成,通常配置参数是将mysql.sock生成在/tmp/目录下.即在/etc/my.cnf文件中指定socket=/tmp/mysql

连接Mysql提示Can’t connect to local MySQL server through socket的解决方法

mysql,Mysqldump,Mysqladmin,php连接mysql服务常会提示下面错误: 1 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 这是由于修改mysql服务的了socket文件mysql.sock位置,而导致无法通过mysql socket文件连接到mysql服务引起的,具体解决办法如下:1.查看mysql服务的sock

Can&#39;t connect to local MySQL server through socket &#39;/tmp/mysql.sock&#39;

启动mysql之后,不能进入mysql命令行: Can't connect to local MySQL server through socket '/tmp/mysql.sock': 修改/etc/my.cnf 当中 socket=/tmp/mysql.sock 重启mysql,即可 Can't connect to local MySQL server through socket '/tmp/mysql.sock'

命令行连接mysql服务器时 报Can&#39;t connect to local MySQL server through socket &#39;xxx.sock&#39;错误

本来之前用的好好的mysql服务器,突然就报Can't connect to local MySQL server through socket 'xxx.sock'错误了 遇到该问题思路首先是:检查 my.cnf 中 socket 配置的路径及权限. 但是查看完 没发现路劲权限有问题,最后跑去另一台同时配置的服务器上看  发现/data/perconadata有一个/mnt/perconadata/mysql.sock的软连接 于是乎到问题机器上 cd /data/perconadata/ s

mysql Can&#39;t connect to local MySQL server through socket &#39;/var/lib/mysql/mysql.sock&#39; (2)

错误原因:/var/lib/mysql目录中socket文件不存在.连接mysql服务器有两种方式:tcp连接,通过socket文件连接.通过socket文件,启动mysql服务,mysql服务会自动生成一个sock文件,生成的sock文件默认放在 --datadir=/var/lib/mysql,mysql默认从/var/lib/mysql目录读取sock文件. 解决办法:1.看看/var/lib/mysql/mysql 有没有mysql.sock文件2.没有mysql.sock,重启mysq

ERROR 2002 (HY000): Can&#39;t connect to local MySQL server through socket &#39;/tmp/mysql.sock&#39; (2)

我在源码编译安装mysql后,虽然mysql服务可以正常启动,但是当我直接执行mysql后,出现了错误. 错误提示如下: [[email protected] ~]# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 出现错误原因: 由于mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,但linux系统总