1

I want to export a database to sql file with Python, so I tried this

import os
os.system('mysqldump -u root -p database > database.sql')

and it asks me to write the password of the root user in the shell, but I'm doing a GUI application, so I don't want the user to interact with the shell.

Is it possible to give it the password in some other way?

1 Answer 1

6

You can prompt the user for the password and insert it into the command.

import os
os.system('mysqldump -u root -p%s database > database.sql' % password)

The syntax is -pmypass or --password=mypass

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

1 Comment

Just because it is so unusual I want to be explicit here: There is NO SPACE between -p and yourpassword!

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.