简体   繁体   中英

mysql dump outside the command line

Do any of the modern programming languages support mysqldump as a method, Or is it still the domain of command line environments.

There are APIs available (database drivers) for .NET, Delphi, and generic ODBC/DAO, as well as libraries for C/C++ and other languages. It's never going to be written directly into a mainstream language itself; that would restrict the language from being as general purpose and therefore make it less useful.

Delphi, for instance, has a database framework called DBExpress; there's a DBExpress driver included out of the box for MS SQL Server, Oracle, MySQL, DB2, and others; what drivers are available depend on the version (Professional, Enterprise, or Architect) you decide to buy. MySQL is available in all versions.

Using the DBExpress framework makes Delphi usable with any database engine that someone decides to provide a DBExpress driver for, and the drivers can be written in Delphi itself. That keeps Delphi more general purpose; it's not hard-coded to work with only a single RDBMS.

EDIT: As others have said (I think Jarret), the source to mysqldump is available. Using the wrappers available for your language of choice, you should be able to implement the same functionality based on that source.

If you're using PHP and don't mind using a GPL license, then phpMyAdmin contains some code for MySQL dump (as well as to other formats like CSV, etc).

Check out the file:

libraries/export/sql.php

Your instinct is right... it would be pretty tough for a programming language library to provide API access to mysqldump. The source to mysqldump is written in C, with its own main() function; it's designed to operate pretty much as its own program. It gets built as an executable, and much of the error reporting and output are handled using direct print statements to stdout, and not using return values that could be wrapped into a language-specific value.

When most bindings for a specific programming language are compiled (PHP, python, Delphi, .NET, etc), they link against libmysql , and libmysql contains no reference to the mysqldump program. I can't say for sure that no one has written a wrapper, but it would be a very bizarre wrapper indeed.

In other words, your best bet is to use a sub-process from your programming language of choice to call the mysqldump tool, and absorb the results either from stdin or from a temp file.

Your question is rather vague. Please describe what you want to accomplish, and what you have tried already.

That being said, if you want to produce a DB dump of a MySQL database in the way that mysqldump does, I know of no API that makes it possible directly. But there are numerous other ways of dumping / backing up a DB, and the mysqldump format has its share of problems (not well defined for one thing, hence not easy to parse). So you might consider an alternative approach.

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