0

I need to execute mysqldump from within a django function. I can do so easily enough from the terminal command line, but when I try to run it from within the python script, I get an error:

sh: mysqldump: command not found 

when running the following.

filestamp = date.today()
dumpcmd = "mysqldump -u root appdb > appdb%s.out" % (filestamp)
os.system(dumpcmd)

I think the problem has something to do with the Path in either the django application or Eclipse, but I can't figure out why mysqldump can't be found from within the django app but it can be from the command line / virtualenv

4
  • You are better off using the management command dumpdata Commented Dec 11, 2016 at 22:35
  • but why do you want to do that? Commented Dec 12, 2016 at 0:12
  • I want to automate the syncing of a database on my local machine with the same database hosted online. The first step I usually pursue is mysqldump, so I'm trying to replicate that programatically. Commented Dec 14, 2016 at 17:34
  • almost a duplicate: stackoverflow.com/questions/38916163/… Commented Dec 17, 2016 at 14:08

1 Answer 1

0

make sure mysqldump is in your path

$ whereis mysqldump; echo $PATH
mysqldump: /usr/bin/mysqldump /usr/share/man/man1/mysqldump.1.gz
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

and/or

using mysqldump and mysql inside python

import subprocess
subprocess.Popen('mysqldump -h localhost -P 3306 -u -root appdb > appdb.sql', shell=True)

Or use the full path in the Python statement. e.g. /usr/bin/mysqldump

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.