Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9210603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:07:00+00:00 2026-06-18T01:07:00+00:00

I have written two small functions in Python to call mysqldump and mysql from

  • 0

I have written two small functions in Python to call mysqldump and mysql from console, so I am able to create a database backup and then restore it:

# Makes a backup current database status
def backupDatabase():
    if(os.path.exists('myDatabaseBackup.sql')):
        os.remove('myDatabaseBackup.sql')
    call(['mysqldump', '-u myUsername myDatabase > myDatabaseBackup.sql'])


# Restores database
def restoreDatabase():
    call(['mysql', '-u myUsername myDatabase < myDatabaseBackup.sql'])

Nevertheless, they are not working. I have read that call gets two values: the executable and the parameters, but it looks that parameters are being ignored, since the output after calling backupDatabase is:

Usage: mysqldump [OPTIONS] database [tables] OR … For more options,
se mysqldump –help

What’s wrong? I know I could use Pipes (I don’t know how at the moment, just know they exist and are an alternative), but since this looks like a pretty simple task I guess subprocess.call should be enough. So, is it possible to fix this with subprocess.call? (If not, please provide some help for Pipes or any other solution).

Also, I’m using MySQLdb package for other purposes, so if it is possible to backup and restore somehow using this package, it would be great.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:07:01+00:00Added an answer on June 18, 2026 at 1:07 am

    First of all, subprocess.call expects you to pass each command line parameter separately, like this:

    subprocess.call(['mysqldump', '-u', 'myUsername'])
    

    Second, to redirect the output, you pass additional stdout argument, which, among other things, can be an open file object:

    with open('myDatabaseBackup.sql', 'w') as fout:
        subprocess.call(['mysqldump', '-u', 'myUsername'], stdout=fout)
    

    (For the second redirection you naturally use stdin. More details are in FAQ)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a Python module, and I have two versions: a pure Python
Hi I have a program written in C++ in which one or two functions
I have a small piece of code, written in python which has a Generate
I have written small C++ console application and this is source code : #include<stdio.h>
I have written two short tests and compiled both with g++ -S (gcc version
I have written two scripts where one script calls subprocess.Popen to run a terminal
I have written two pieces of code which I intended to have identical outputs,
I have written an app in C which expects two lines at input. First
I have written a module similar to the following: module One class Two def
I have two window form applications written in C, one holds a struct consisting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.