Backup and Restore MySQL Database-VBForums
Results 1 to 2 of 2

Thread: Backup and Restore MySQL Database

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2006
    Posts
    53

    Smile Backup and Restore MySQL Database

    ATTENTION:
    this thread just for newbie like me

    for the backup mysql database from VB6, we simply use the MySQL tool MySQLDump and for restore using the mysql.

    this a basic commands to backup and restore mysql database:

    Code:
    ' backup
    mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
    or 
    mysqldump -uUSER_NAME -pUSER_PASSWORD --routines DB_NAME > dumpfilename.sql
    
    ' restore
    mysql -uUSER_NAME -pUSER_PASSWORD DB_NAME < dumpfilename.sql
    --routines : use this parameter if u database have a function/trigger
    HOW to implement it in VB6?
    OK, prepare the following code :

    Function Code:
    1. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    2. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    3. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    4.  
    5. Private Const SYNCHRONIZE       As Long = &H100000
    6. Private Const INFINITE          As Long = &HFFFF
    7.  
    8. Private Sub execCommand(ByVal cmd As String)
    9.     Dim result  As Long
    10.     Dim lPid    As Long
    11.     Dim lHnd    As Long
    12.     Dim lRet    As Long
    13.  
    14.     cmd = "cmd /c " & cmd
    15.     result = Shell(cmd, vbHide)
    16.  
    17.     lPid = result
    18.     If lPid <> 0 Then
    19.         lHnd = OpenProcess(SYNCHRONIZE, 0, lPid)
    20.         If lHnd <> 0 Then
    21.             lRet = WaitForSingleObject(lHnd, INFINITE)
    22.             CloseHandle (lHnd)
    23.         End If
    24.     End If
    25. End Sub

    then, use this code for backup or restore the MySQL Database
    Backup-Restore DB Code:
    1. Dim cmd As String
    2.  
    3. Private Sub cmdBackup_Click()
    4.     Screen.MousePointer = vbHourglass
    5.     DoEvents
    6.  
    7.     cmd = Chr(34) & "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump" & Chr(34) & " -uroot -psecretpswd --routines --comments db_name > c:\MyBackup.sql"
    8.     Call execCommand(cmd)
    9.  
    10.     Screen.MousePointer = vbDefault
    11.     MsgBox "done"
    12. End Sub
    13.  
    14. Private Sub cmdRestore_Click()
    15.     Screen.MousePointer = vbHourglass
    16.     DoEvents
    17.  
    18.     cmd = Chr(34) & "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql" & Chr(34) & " -uroot -psecretpswd --comments db_name < c:\MyBackup.sql"
    19.     Call execCommand(cmd)
    20.  
    21.     Screen.MousePointer = vbDefault
    22.     MsgBox "done"
    23. End Sub

    I hope this article helps you
    Last edited by Hack; May 10th, 2012 at 07:16 AM.

  2. #2
    Hyperactive Member
    Join Date
    Oct 2010
    Posts
    377

    Re: Backup and Restore MySQL Database

    I would like to know how to restore all database to the server at once
    that is why I asked if the sytax below is correct.


    mysqldump -u root -p password --all-databases < c:\databases.sql

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.