up vote 0 down vote favorite
share [g+] share [fb]

I have mysql dump command that I would like to run from from windows shell or command prompt. I have used shell it does work.

  d= 'BkSql_'+datetime.datetime.now().strftime("%Y-%m-%d")+".sql"
  fn = dn+d    
  cmd="""mysqldump -u hapopdy -p   > %s""" %fn
  print cmd

Edit::::::: The -p needs to be a raw input.

link|improve this question

78% accept rate
feedback

2 Answers

up vote 5 down vote accepted

Using the subprocess module

import subprocess
subprocess.call(cmd)

If you're running a shell command add shell=True

subprocess.call(cmd, shell=True)
link|improve this answer
tested with cmd = r"""copy c:\x\fails.txt c:\x\copiedfails.txt""" didnt work.... – Merlin Aug 17 '11 at 23:38
1  
copy on windows is a shell command, not an executable. Try subprocess.call(cmd, shell=True) – orip Aug 18 '11 at 4:33
feedback

You should save the password in mysql's local configuration file for the user.(In Unix it's ~/.my.cnf) or you can give it on the command line with --password=MYPASSWORD.

Either way, the password will be visible to a large audience. In the .my.cnf case, it will be visible to anyone with read access to the file. In the second case, it will be visible to anyone who can get a process listing on the system, in addition to those who have read access to your script.

link|improve this answer
could I create a user that only could dump database/ – Merlin Aug 17 '11 at 23:43
feedback

Your Answer

 
or
required, but never shown

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