重庆思庄Oracle、Redhat认证学习论坛

标题: mysqldump: Got error: 2002: Can't connect to local MySQL server through socke... [打印本页]

作者: jiawang    时间: 2024-8-6 20:34
标题: mysqldump: Got error: 2002: Can't connect to local MySQL server through socke...
本帖最后由 jiawang 于 2024-8-6 20:34 编辑

使用mysqldump备份所有数据库报错:
[root@sztech ~]# mysqldump -uroot -p --socket=/data/mysql/mysql.sock --all-databases > all_databases_backup.sqlEnter password:
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/data/mysql/mysql.sock' (2) when trying to connect


因为mysql的socket文件读取异常(文件可能已删除),导致socket无法连接所致


确认当前MySQL的socket
[root@sztech ~]# netstat -ln | grep mysql
unix  2      [ ACC ]     STREAM     LISTENING     243800   /var/lib/mysql/mysql.sock

用正确的socket文件连接mysql,再次执行mysqdump命令:
[root@sztech ~]# mysqldump -uroot -p --socket=/var/lib/mysql/mysql.sock --all-databases > all_databases_backup.sql
Enter password:
[root@sztech ~]# ll
total 864
-rw-r--r--. 1 root root 873551 Aug  5 18:15 all_databases_backup.sql








欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2