Reputation: 76
I am trying to backup MySQL database but if the command run outside of the application manually it works fine but if it's executed from within the application it gives the error "using password on the command line interface can be insecure" and nothing happens but as I said it I run same command through cmd or a .bat file it work properly, so how to fix it ? and here is the code I am trying
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
I alternately already tried this as well gives the same error
Process.Start(--host=localhost --user=****--password=****-R airtech_db > " & Application.StartupPath & "\adil.sql)
Upvotes: 0
Views: 309
Reputation: 76
well thats what i did to make it work I made an .bat file to run my command to make backup for me
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 If
Upvotes: 1