Python Forum

Full Version: Warning password insecure - Mysql backup with Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I made this little script with Python to create a backup of a table from my database:

import subprocess
sql_cmd = 'mysql -B -uUser -p password database -e "SELECT * FROM device;" > file.csv'
subprocess.run([sql_cmd], shell=True)
It is working, but I got this warning message:

mysql: [Warning] Using a password on the command line interface can be insecure.

I would like to solve this problem if someone can help me please Smile

Thanks ^^
OS?..
Quote:The message is too short. Please enter a message longer than 5 characters.
Next time I will add periods like that
That looks like a MySQL warning. You could try a way to securely store the password.
Instead of using subprocess to invoke the command line client, you could use a mysql api to query the database directly. That would eliminate the "password using command line" issue.
As mention bye @nilamo there are tool for this in Python to connect directly.
PyMySQL pure-Python MySQL client library
mysqlclient