After all, mysqldump is just a wrapper for the command that I'm looking for.
No, it actually isn't.
Some of the other utilities like mysqladmin and mysqlcheck are not much more than "convenient" (or, if you ask me, largely pointless) wrappers for SQL statements you can issue yourself, so I suppose your assumption could be reasonable in that light, but that's not case with mysqldump.
The source code for mysqldump is ~5,061 lines of C -- and that's not even including the code that actually manages the TCP or Unix socket communication with the MySQL server or a lot of other common code libraries that are shared among the MySQL Server and the utilities.
Yes, the mysqldump utility does -- where practical -- assemble some SQL statements, send them to the server for execution, and write the server's response in the dump file...
my_snprintf(query, sizeof(query), "SHOW CREATE TABLE %s", result_table);
... that one's kind of a no-brainer, pretty much a wheel that need not be reinvented.
However, there are a number of operations that it performs that are not at all handled by the MySQL server code. Examples...
if (opt_drop_trigger)
fprintf(sql_file, "/*!50032 DROP TRIGGER IF EXISTS %s */;\n", (*show_trigger_row)[0]);
fprintf(sql_file,
"DELIMITER ;;\n"
"/*!50003 SET SESSION SQL_MODE=\"%s\" */;;\n"
"/*!50003 CREATE */ ",
(*show_trigger_row)[6]);
There is no functionality inside mysql to do what that does, or this...
if (write_data)
{
if (opt_replace_into)
dynstr_append_checked(&insert_pat, "REPLACE ");
else
dynstr_append_checked(&insert_pat, "INSERT ");
dynstr_append_checked(&insert_pat, insert_option);
dynstr_append_checked(&insert_pat, "INTO ");
dynstr_append_checked(&insert_pat, opt_quoted_table);
if (complete_insert)
{
dynstr_append_checked(&insert_pat, " (");
}
else
{
dynstr_append_checked(&insert_pat, " VALUES ");
if (!extended_insert)
dynstr_append_checked(&insert_pat, "(");
}
}
while ((row= mysql_fetch_row(result)))
{
if (complete_insert)
{
if (init)
{
dynstr_append_checked(&insert_pat, ", ");
}
init=1;
dynstr_append_checked(&insert_pat,
quote_name(row[SHOW_FIELDNAME], name_buff, 0));
}
}
num_fields= mysql_num_rows(result);
mysql_free_result(result);
That seems like a lot of unnecessary work for a wrapper. :) You may have worked out by now, that's an example of some of the simple things mysqldump does, reading the row data coming back from the server in a packed binary format after it issues the SELECT /*!40001 SQL_NO_CACHE */ * FROM ... to fetch all of the data from each table, and converting it into SQL statements. The code that actually crafts those INSERT statements is from mysqldump. Not in the server.
There's a reason why everything on the Internet points to mysqldump.