0

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)
oliva nikita
  • 76
  • 1
  • 10
  • There are several answers in [Suppress warning messages using mysql from within Terminal, but password written in bash script])(https://stackoverflow.com/questions/20751352/suppress-warning-messages-using-mysql-from-within-terminal-but-password-written) which might help you. Or you could examine the source code for something like [MySqlBackup.Net](https://github.com/MySqlBackupNET/MySqlBackup.Net). – Andrew Morton Jun 13 '20 at 16:11
  • well the reference you provided me i couldn't get any of it as I am working with mysqldump.exe to backup MySQL database record plus they make cnf file so I don't know how to run backup command with having password in the cnf file – oliva nikita Jun 13 '20 at 16:21

1 Answers1

1

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
oliva nikita
  • 76
  • 1
  • 10