Closed AFDevMike closed 14 minutes ago
No, there's nothing directly analogous.
I don't actually know how mysql source
works but I assume it would have to stream the dumped .sql
file to MySQL Server in a series of COM_QUERY
packets. Most likely, it parses the input file into a series of SQL statements and executes each one individually on the server. (Possibly with some special handling for USE
statements or anything else that needs to update client-side state rather than (or in addition to) server-side state.)
I think you would need to do something similar; i.e., in pseudocode:
var lines = File.ReadLines(inputSqlFile);
foreach (var statement in ParseLinesIntoStatements(lines))
{
using var command = connection.CreateCommand();
command.CommandText = statement;
command.ExecuteNonQuery();
}
Obviously the complexity is all in ParseLinesIntoStatements
which worst case is completely rewriting the SQL parsing from mysql
CLI in C#.
Is there a direct analog to:
mysql -u -p theDb < c:\GiantDbBackup.sql
ORmysql source c:\GiantDbBackup.sql
Alternatively, is there an option to execute a MySqlCommand where is source is a
stream
?