MySQL备份 - 警告密码不安全

时间:2017-06-07 12:31:25

标签: python mysql security warnings

我使用Python创建了这个小脚本,以便从数据库创建表的备份:

import subprocess
sql_cmd = 'mysql -B -u User -pPassword  -e Database "SELECT * FROMdevice;" > file.csv'
subprocess.run([sql_cmd], shell=True)

它正在运行,但我收到了此警告消息:mysql: [Warning] Using a password on the command line interface can be insecure.

如果可能,我想隐藏或删除警告。

1 个答案:

答案 0 :(得分:0)

从输入中获取密码

import subprocess
import getpass

pswd = getpass.getpass('Password:')
sql_cmd = 'mysql -B -u User -p pswd  -e Database "SELECT * FROMdevice;" > 
file.csv'
subprocess.run([sql_cmd], shell=True)