Same question has been asked here but its not helping me out.

In my python utility, I'm trying to take MySQL database backup using mysqldump. It runs successfully but I'm getting 0kb file in my backup folder.

This is my code;

DB_HOST = ''
DB_USER = 'root'
DB_USER_PASSWORD = '_root_user_password_'
DB_NAME = 'db_name'
BACKUP_PATH = '/backup/dbbackup/'

DATETIME = time.strftime('%m%d%Y-%H%M%S')

dumpcmd = "mysqldump -h " + DB_HOST + " -u " + DB_USER + " -p" + DB_USER_PASSWORD + " " + db + " > " + TODAYBACKUPPATH + "/" + db + ".sql"


Can anyone guide me out that what I'm missing here??


2 Answers 2


Some troubleshooting:

  • Run the command (dictated by dumpcmd) from the command-line and see if there are any errors
  • Does the password have any special characters in it that could mess up in a shell
  • Try changing mysqldump to the full path, eg: /usr/local/bin/mysqldump
  • Check the return value from os.system() in your script

Changing to the full path appears to be what you were looking for.


I was doing the same thing but I ran my script on a Windows host and the user running the job in task scheduler did not have admin rights on the machine, or in fact any rights since it was a domain account, and hence produced a 0kb file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.