---
title: "linux导出数据库报错：Can't connect to local MySQL server through socket '/tmp/mysql.sock"
author: "MNTMs"
date: "2015-06-03T19:23:26Z"
tags: []
categories: ["编程语言"]
slug: "linux-can-t-connect-to-local-mysql-server-through-socket-tmp-mysql-sock"
draft: false
lastmod: "2015-06-03T19:23:26Z"
id: 2216769
url: "https://mntms.iteye.com/blog/2216769"
---

在执行mysqldump命令时候报如下错误：

\[root@localhost ~]#  mysqldump -uroot -p -d test&gt; test.sql   

mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect

 

找到正确的套接字的路径： 

\[root@localhost ~]#  netstat -ln | grep mysql                                   

unix  2      \[ ACC ]     STREAM     LISTENING     70442911 /MysqlData/base/mysql/mysql.sock

 

 

再运行dump命令：

\[root@localhost ~]# mysqldump --sock=/MysqlData/base/mysql/mysql.sock -uroot -p -d test&gt; test.sql   

Warning: Using unique option prefix sock instead of socket is deprecated and will be removed in a future release. Please use the full name instead.

Enter password: 

执行成功，但有警告信息，提示使用sock前辍将在后继版本中可能不再支持，请使用全名

将--sock 换成--socket将不再有问题：

 

\[root@localhost ~]# mysqldump --socket=/MysqlData/base/mysql/mysql.sock -uroot -p -d test&gt; test.sql