专题推荐
专题推荐

Linux vps备份数据库提示mysqldump: Got error: 2002: Can’t connect to local MySQL server through socket

2020-01-31 17:47 分类:VPS教程 阅读(次阅读) 标签:,

在执行mysqldump命令备份数据库到本地时报错如下:

[root@wpyi bin]# mysqldump -uwpyi_com -pbd9UbEaAKefdhsfR wpyi_com > "/home/beifen/wpyi.sql"
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect

原因是没有找到正确的路径:

通过 netstat -ln | grep mysql 命令查找

[root@wpyi bin]# netstat -ln | grep mysql
unix 2 [ ACC ] STREAM LISTENING 28837 /tmp/mysql-generic-5.5.sock

于是修改为

[root@wpyi bin]# mysqldump --socket=//tmp/mysql-generic-5.5.sock -uwpyi_com -pbd9UbEaAKefdhsfR wpyi_com > "/home/beifen/wpyi.sql"

同时你也可以看下这篇类似问题:
https://www.vpsyi.com/mysqldump-command-not-found.html


本文地址: https://www.vpsyi.com/mysqldump-got-error-2002.html