MySQLDump – How to Fix 0KB Backup Issue

MySQLmysqldumppython

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 = '192.168.1.1'
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')
TODAYBACKUPPATH = BACKUP_PATH + DATETIME

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

os.system(dumpcmd)

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

Best Answer

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.

Related Question