8

记一次使用sqlbackup备份数据库失败,错误Can't connect to local MySQL server throu...

 2 years ago
source link: https://hellodk.cn/post/46
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

记一次使用sqlbackup备份数据库失败,错误Can't connect to local MySQL server through socket的解决过程

使用/opt/bin/sqlbackup命令备份数据库时,得到如下错误:

# /opt/bin/sqlbackup
mysqldump: Got error: 2002: "Can't connect to local MySQL server through socket '/opt/var/run/mysqld.sock' (2)" when trying to connect

使用mysqladmin -u root -p status查看状态,结果如下:

# mysqladmin -u root -p status
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/opt/var/run/mysqld.sock' (2)' Check that mysqld is running and that the socket: '/opt/var/run/mysqld.sock' exists!

解决办法当然也知道是修改my.cnf文件。

vim /opt/etc/mysql/my.cnf

感谢Stackoverflow这篇帖子,https://stackoverflow.com/questions/5376427/cant-connect-to-local-mysql-server-through-socket-var-mysql-mysql-sock-38我用如下截图用户「AnupRaj」的方法解决了问题,感谢感谢。

mysql Cant connect to local MySQL server through socket

my.cnf中的bind-address字段修改为localhost后,保存退出并重启onmp服务,执行sqlbackup没有出错,ok.

附录一下,cron程序位于/etc/init.d/cron,其脚本文件(文本文件)是/etc/crontabs/root,添加如下命令:

1 */72 * * * /opt/bin/sqlbackup

说明:这代表每隔72小时(3天3夜)自动执行一次/opt/bin/sqlbackup,自动备份数据库

标签: MySQL

本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK