Hello there.. I want to backup my database (MySQL) using a command button in VB6...How can I do that? thank you for answering... :)

Dani AI

Generated

A practical note tied to the replies: copying files from the MySQL data folder (what suggested and what confirmed worked) can be fine for an offline server or simple MyISAM setups, but it is unsafe for a running server—InnoDB tables can become inconsistent. For reliable, repeatable backups use a logical dump (mysqldump) or a hot-physical backup tool for production databases.

A compact VB6 pattern is to run mysqldump from the app, wait for it to finish, and check the exit code. The example below uses an external credentials file (so the password is not visible on the command line) and --result-file to avoid shell redirection:

Private Sub cmdBackup_Click()
    Dim wsh As Object, execObj As Object
    Dim cmd As String, ts As String, mysqldumpPath As String, resultFile As String

    mysqldumpPath = "C:\Program Files\MySQL\bin\mysqldump.exe"
    ts = CStr(Year(Now)) & Right$("0" & Month(Now),2) & Right$("0" & Day(Now),2) & "_" & _
         Right$("0" & Hour(Now),2) & Right$("0" & Minute(Now),2) & Right$("0" & Second(Now),2)
    resultFile = App.Path & "\backups\mydb_" & ts & ".sql"

    cmd = """" & mysqldumpPath & """" & " --defaults-extra-file=""" & App.Path & "\my.cnf""" & _
          " --databases mydb --single-transaction --quick --routines --triggers" & _
          " --result-file=""" & resultFile & """"

    Set wsh = CreateObject("WScript.Shell")
    Set execObj = wsh.Exec(cmd)
    Do While execObj.Status = 0: DoEvents: Loop

    If execObj.ExitCode = 0 Then
        MsgBox "Backup created: " & resultFile
    Else
        MsgBox "Backup failed: " & execObj.StdErr.ReadAll
    End If
End Sub

Notes and cautions: create the small credentials file (a [client] section with user/password) and lock its NTFS permissions; avoid --password= on the command line; verify restores regularly; compress/rotate old dumps and ensure sufficient disk space; for large production systems consider Percona XtraBackup or MySQL Enterprise Backup rather than logical dumps. 's ADO/ADODC route can be used to export data programmatically, but it requires more work to reproduce schema, routines, and exact DDL compared with mysqldump.

Recommended Answers

All 8 Replies

FileSystemObject.CopyFile "c:\mydocuments\letters\ *.doc", "c:\tempfolder\"

it didn't work :3

Dim SourceFile, DestinationFile As String
SourceFile = "SRCFILE" ' Define source file name.
DestinationFile = "DESTFILE" ' Define target file name.
FileCopy(SourceFile, DestinationFile) ' Copy source to target.

Also show us the code you are using

Im sorry to say but I don't have any codes from it..It is my first time to backup a database of MySQL using VB6..I'm just a newbie :)

O.K- create a command button
You need the location and the filename of the file you want to copy. You need a location where you want it copy to and you need to give a filename.

Private Sub Command1_Click()
FileCopy "C:\1.txt", "C:\Folder1\2.txt"
End Sub

here you can see that c:\ is the source directory
1.txt is the filename that get copied to c:\ directory into folder Folder1 as file 2.text

or else used a adodc1 for linking used Adodc1.Connecstring="app.path"

Thanks a lot guys! It works! :)

Please mark it solved. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.