我正在尝试备份MySQL数据库,但如果命令手动运行在应用程序之外,它工作得很好,但如果它是从应用程序内部执行的,它会给出错误“使用命令行界面上的密码可能不安全”,什么也没有发生,但正如我所说的,我通过cmd或.bat文件运行相同的命令,它工作正常,那么如何修复它呢?下面是我正在尝试的代码
Private Sub BACKUP_BTN_Click(sender As Object, e As EventArgs) Handles BACKUP_BTN.Click
Using myProcess As New Process()
Dim newfiledb As String = Application.StartupPath & "\" & Format(Now(), "MMM_dd_yyyy@h~mm_tt").ToString & "_local.sql"
Try
myProcess.StartInfo.FileName = Application.StartupPath & "\mysql-8.0\bin\mysqldump.exe"
myProcess.StartInfo.WorkingDirectory = Application.StartupPath
myProcess.StartInfo.Arguments = "--host=localhost --user=****--password=*****-R airtech_db > " & Application.StartupPath & "\filename.sql"
'myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.Start()
myProcess.WaitForExit()
Label1.Text = " MsgBox(Backup Created ... & vbNewLine & newfiledb)"
Catch ex As Exception
MsgBox(ex.Message, vbCritical + vbOKOnly, ex.Message)
Finally
myProcess.Close()
End Try
End Using我也已经尝试过了,也给出了相同的错误
Process.Start(--host=localhost --user=****--password=****-R airtech_db > " & Application.StartupPath & "\adil.sql)发布于 2020-06-14 00:24:18
这就是我所做的让它工作,我做了一个.bat文件来运行我的命令,为我做备份
Private Sub BACKUP_BTN_Click(sender As Object, e As EventArgs) Handles BACKUP_BTN.Click
Dim run_bat_file As String = Application.StartupPath & "\mysql-8.0\bin\RUN.BAT"
If Directory.Exists(Application.StartupPath & "\Backup_db") = False Then Directory.CreateDirectory(Application.StartupPath & "\Backup_db")
If File.Exists(run_bat_file) = False Then
File.Create(run_bat_file).Dispose()
End If
If System.IO.File.Exists(run_bat_file) = True Then
Dim objWriter As New System.IO.StreamWriter(run_bat_file, False), log As String
log = "mysqldump.exe --host=localhost --user=****--password=****-R airtech_db > ..\..\backup_db\" & Format(Now(), "MMM_dd_yyyy@h~mm_tt").ToString & "_airtech_db.sql" & Environment.NewLine & "pause"
objWriter.Write(log)
objWriter.Close()
'MsgBox("Text written to file")
Using MYPROCESS As New Process
MYPROCESS.StartInfo.FileName = Application.StartupPath & "\mysql-8.0\bin\RUN.BAT"
MYPROCESS.StartInfo.WorkingDirectory = Application.StartupPath & "\mysql-8.0\bin"
MYPROCESS.Start()
MYPROCESS.WaitForExit()
Label1.Text = "BACKUP STARTED...."
End Using
Else
MsgBox("File Does Not Exist", vbCritical + vbOKOnly, "Error")
End Ifhttps://stackoverflow.com/questions/62361035
复制相似问题