简体   繁体   中英

SqlBulkCopy equivalent in MySql?

I am more used to SQL Server and I'd like to know if in MySql I can find something analog to SqlBulkCopy. I have a data editor written in WPF/Silverlight and C# using Connector/NET to connect to a MySql server, and I should provide a function inside the editor to make a full backup of some MySql databases. I have no direct access to the server so I cannot use dump or other command-line tools.

What would then the best way of dumping a whole database using only C# code via Connector? I just have to massively export data into XML, CSV or the like with my own SQL queries, or is there any suggested way for such tasks?

Sounds like MySQL LOAD DATA might be what you are looking for. See the docs here .

You could also use OUTFILE (from the same doc page), for example:

SELECT * INTO OUTFILE 'somefile.txt'
FIELDS TERMINATED BY ','
FROM your_table;

SELECT INTO OUTFILE is the standard way to do this, but it can only dump data to the server's local file system. If you don't have access to the server, you won't be able to access the dump files.

I'd suggest a combination of

SHOW CREATE TABLE XXXX to retrieve the table sql, and some form of SELECT * FROM XXXX to retrieve the data. The Maatkit tools might be useful as reference. You could figure out what it's doing and copy the SQL:

http://www.maatkit.org/doc/mk-archiver.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM