locked
Backup Restore Mysql RRS feed

  • Question

  • Hi people Im trying to create a form that lets you backup and restore data from a mysql file,
    so far this is the code I use:
    process.start(process,arguments)

    in which process.start(process is "...mysql/bin/mysqldump.exe") which pretty much is the process that lets you do backups.
    and the arguments--> process.start(process,arguments: "-u username -p --opt database > c:\backup.sql")
    when I input all of that however it doesnt generate any backup,
    it does when I use "-u username -p --opt database > -r ""c:\backup.sql"")" in arguments however it doesnt include the data.

    Now the weird thing is that when Im in the command prompt (famous cmd) the command works flawlessly:
    mysqldump -u username -p --opt database >c:\backup.sql it creates the backup sql file with the commands to generate the data,

    What am I doing wrong here? is there another way to make the backup?
    or another way to execute the process and the arguments?
    Regards,
    Hugo.
    Tuesday, March 4, 2008 4:20 AM

Answers

  • Hi Hugo,


    Try the following code snippet. Also read MySQL 5.1 Reference Manual for more information about MySql.

    Imports MySql.Data.MySqlClient
    Imports System.IO
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Process.Start("E:\tool\MySql\bin\mysqldump.exe", " --host=localhost --user=root --password=pwd test -r ""C:\backup1.sql"" ")
        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim myProcess As New Process()
            myProcess.StartInfo.FileName = "cmd.exe"
            myProcess.StartInfo.UseShellExecute = False
            myProcess.StartInfo.WorkingDirectory = "c:\"
            myProcess.StartInfo.RedirectStandardInput = True
            myProcess.StartInfo.RedirectStandardOutput = True
            myProcess.Start()
            Dim myStreamWriter As StreamWriter = myProcess.StandardInput
            Dim mystreamreader As StreamReader = myProcess.StandardOutput
            myStreamWriter.WriteLine("E:\tool\MySql\bin\mysql.exe --host=localhost --user=root --password=pwd test < backup1.sql ")
            Dim str As String = mystreamreader.ReadToEnd
            MessageBox.Show(str)
            myStreamWriter.Close()
            myProcess.WaitForExit()
            myProcess.Close()
        End Sub
    End Class

    Best regards,
    Riquel
    Friday, March 7, 2008 2:04 PM
    Moderator
  • hi,

     

    This works perfectly,

     

    Process.Start("C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump.exe", " --host=localhost --user=user    --password =password test2  -r ""C:\back2.sql"" ")

     

    u might be wondering what is the difference between the code you use and this. Well the only difference is that you

     

    your code = " >-r "

    this code = "-r"

     

    yes when you leave out the ">" it works in vb.net, i faced the same problem as you too when i used the code you used.

     

    But I can't seem to find the code to backup the mysql dump file. Please somebody help me.

     

    Wednesday, March 5, 2008 9:26 AM

All replies

  • hi,

     

    This works perfectly,

     

    Process.Start("C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump.exe", " --host=localhost --user=user    --password =password test2  -r ""C:\back2.sql"" ")

     

    u might be wondering what is the difference between the code you use and this. Well the only difference is that you

     

    your code = " >-r "

    this code = "-r"

     

    yes when you leave out the ">" it works in vb.net, i faced the same problem as you too when i used the code you used.

     

    But I can't seem to find the code to backup the mysql dump file. Please somebody help me.

     

    Wednesday, March 5, 2008 9:26 AM
  • Hi Hugo,


    Try the following code snippet. Also read MySQL 5.1 Reference Manual for more information about MySql.

    Imports MySql.Data.MySqlClient
    Imports System.IO
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Process.Start("E:\tool\MySql\bin\mysqldump.exe", " --host=localhost --user=root --password=pwd test -r ""C:\backup1.sql"" ")
        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim myProcess As New Process()
            myProcess.StartInfo.FileName = "cmd.exe"
            myProcess.StartInfo.UseShellExecute = False
            myProcess.StartInfo.WorkingDirectory = "c:\"
            myProcess.StartInfo.RedirectStandardInput = True
            myProcess.StartInfo.RedirectStandardOutput = True
            myProcess.Start()
            Dim myStreamWriter As StreamWriter = myProcess.StandardInput
            Dim mystreamreader As StreamReader = myProcess.StandardOutput
            myStreamWriter.WriteLine("E:\tool\MySql\bin\mysql.exe --host=localhost --user=root --password=pwd test < backup1.sql ")
            Dim str As String = mystreamreader.ReadToEnd
            MessageBox.Show(str)
            myStreamWriter.Close()
            myProcess.WaitForExit()
            myProcess.Close()
        End Sub
    End Class

    Best regards,
    Riquel
    Friday, March 7, 2008 2:04 PM
    Moderator
  • Hi Lingeswari,

    For further question about mysql database, please post your question to MySQL forum.

    Best regards,
    Riquel

    Friday, March 7, 2008 2:07 PM
    Moderator
  • I Used ur code to take the backup of a database. But it creates only the database, it didn't copy the existing tables structure and datas. How to do that?
    Monday, December 28, 2009 8:51 AM
  • I Used ur code to take the backup of a database. But it creates only the database, it didn't copy the existing tables structure and datas. How to do that?
    Tuesday, December 29, 2009 8:46 AM
  • I Used ur code to take the backup of a database. But it creates only the database, it didn't copy the existing tables structure and datas. How to do that?
    Tuesday, December 29, 2009 8:46 AM