Click here to Skip to main content
15,935,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

i'm trying to get backup to mysql database. I used this code

private void button1_Click(object sender, EventArgs e)
    string Coonstring = "datasource=localhost;port=3306;username=****;password=****;Charset=utf8";
    MySqlConnection cn= new MySqlConnection(Coonstring);
    MySqlCommand cmd;
    SaveFileDialog sf = new SaveFileDialog();
    sf.Filter = "Backup Files (*.Bak) |*.bak";
        cmd = new MySqlCommand("Backup Database project To Disk='" + sf.FileName + "'", cn);

but i get error ( An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll

Additional information: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Backup Database project To Disk='C:\Users\tariq emad\Desktop\1\tt.bak'' at line 1).

So, any one can help me to fix this error?

Mysql does not natively have backup command (like the MSSQL one in your code), read the following on how to backup :[^]
Share this answer
Dear Mehdi,

this is via shell or telnet.
I need it from C# button code

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900