开发者

MySQL database backup

开发者 https://www.devze.com 2023-01-28 21:14 出处:网络
I am developing a project in VB6. In one menu named DATABASE BACKUP, am trying 开发者_运维技巧to take a database backup from user interface (ie BACKUP.frm form). In SQL Server I tried this & execu

I am developing a project in VB6. In one menu named DATABASE BACKUP, am trying 开发者_运维技巧to take a database backup from user interface (ie BACKUP.frm form). In SQL Server I tried this & executed successfully, but taking a backup from MySQL is somewhat critical to me.

Any solutions?

MY SQL SERVER CODE

If Trim(dbName) <> vbNullString Then
Set oDatabase = oSQLServer.Databases(dbName, Trim(txtLogin))
Set oBackup = New SQLDMO.Backup

oBackup.Database = dbName                  '''set database name
oBackup.Files = Dir1.Path & "\" & dbName & ".bak"       '''file path
oBackup.Action = SQLDMOBackup_Database     '''complete backup
oBackup.SQLBackup oSQLServer               ''backup


You're using SQLDMO, the SQL Data management objects, to do that backup. That library is +specifically+ for SQL Server, won't work with anything else, mysql, oracle, whatever.

for MySql, you'll need to lookup the actual SQL command used to perform the backup and invoke it as you would a normal SQL select, through a connection object.

Hmm, just looked and it doesn't look like MYSQL has any kind of SQL command for that. Looks like you have to shell to MYSQLDUMP.exe


Yes...mysqldump is the solution but ensure it is in Windows path or exists locally.

Assuming: username = root + password = root + Database to backup is called main + You want to save the backup in C:\MySQLBackups + The backup file to create is called main_22@AM.sql

Then the DOS Window shell command looks like this:

mysqldump -u root -proot main > "C:\MySQLBackups\main_22@AM.sql"

Restore is a bit more tricky because the database must already exist. If it does not you must first create it. To restore this backup the DOS window shell command is:

mysql -u root -proot main < "C:\MySQLBackups\main_22@AM.sql"

I write this into a batch file then execute a shell to the batch file from within my VB6 app. Works perfectly for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号