使用/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,自动备份数据库

end.