crontab - mysqldump is using different socket
0
votes
0
answers
20
views
First, I have already permanently set the PATH directory of MySQL in my
.bashrc
so I can use it in terminal in any directory. To verify this process, I restarted my computer, open the terminal and use the command mysql
without navigating into any directory. I can also use mysqldump
in any directory in terminal. I am using xampp, and it was installed in /opt/lampp/
.
I have no problem at all when using mysql or mysqldump in terminal
What I don't understand, and what I want to fix is when using mysqldump in crontab.
So I have this script on my desktop, with the filename of mysqldump.sh
. What's inside is; mysqldump -u root thedatabase > /media/sfadmin/BACKUP/db_'date +\%Y'.sql 2> /media/sfadmin/BACKUP/crontab_error.log
The problem here is the mysqldump is not working and is throwing me an error of: mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when trying to connect
which I don't understand why.
I have also tried to change the code in my script to; (cd /opt/lampp/bin/ && mysqldump -u root thedatabase > /media/sfadmin/BACKUP/db_'date +\%Y'.sql 2> /media/sfadmin/BACKUP/crontab_error.log)
which still no luck.
what is wrong? why the crontab is using the socket of /var/run/mysqld/mysqld.sock
? How can I fix that?
Anyway, the crontab is */1 * * * * /home/sfadmin/Desktop/mysqldump.sh
. This should execute mysqldump every minute.
All the configurations are the default for MySQL, I didn't put any password or anything.
**EDIT**: Let's say that the said duplicate post solves this problem, which is about setting the environment variables for the cron to use, then how come this thing work;
- Perform a clean install of ubuntu (same version)
- Install Xampp
- Setting the PATH directory of MySQL in my .bashrc
- Create a file mysqldump.sh
on the desktop, and make it executable.
- Add this code in the script mysqldump.sh
: `mysqldump -u root
thedatabase > /media/sfadmin/BACKUP/db_'date +\%Y'.sql 2>
/media/sfadmin/BACKUP/crontab_error.log`
- execute crontab -e
in terminal, and save this */1 * * * * /home/sfadmin/Desktop/mysqldump.sh
.
How come the same method works in a fresh install without doing the said duplicate post?
Asked by Bolomeo
(101 rep)
Jun 14, 2022, 03:58 AM
Last activity: Jun 14, 2022, 09:15 AM
Last activity: Jun 14, 2022, 09:15 AM