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# u开发者_JS百科sing 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
精彩评论