mysql dump outside the command line - mysql

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

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

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.

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.

Related

Can I connect to SQL with Node.JS without an external package, or with one universal package?

I know it may be reinventing the wheel to some extent, but I'm creating a package of my own in Node.JS where I would like to keep dependencies to an absolute minimum. This program should connect to SQL (at first, just MySQL, but eventually several different flavors, so if the same answer applies to PostgreSQL, MSSQL, etc. a note about that would be much appreciated) and be able to run queries and such. Is there a way to do so through Node without using an external package like mysql or mssql?
I do understand that this sounds very impractical, and so I see the need to use "fully debugged open-source software" as the commenter put it. However, requiring a new package for every SQL flavor I extend my program to would be impractical as well. If I must install a package, is there some sort of universal one that I can use for Node.JS (something like PDO in PHP)? If so, what is the basic way of connecting to, say, MySQL?
Thanks in advance.
Node has RDBMS-specific packages like mysql, pg, sqlite3, mssql, ibm_db, oracledb, ... all the same except where they aren't.
The php world boasts a couple of database abstraction layers that can talk to multiple makes and models of RDBMS. For Java, JDBC serves the same purpose.
The npm ladc package is a similar project for nodejs; it uses the existing packages for connecting to databases. It seems to be in an early version and not heavily used, according to its npm page.
Sequelize is an object-relational database abstraction above some RDBMSs. If you are able to use an object-relational model for your data, it's probably a good choice. If you're using lots of pure SQL, ladc might make sense.
It seems as if you're blazing a trail with your project.

MySQL -- What language to use for DBA automation? (Perl, Python...?)

I've inherited an existing MySQL (5.x) instance and there's been little to no maintenance of the system
My question as a MSSQL DBA is -- What tools are most commonly used to automate administrative tasks when scripting/automation MySQL tasks?
For my MSSQL servers I mainly use native T-SQL, PowerShell or C# to create my automation processes. T-SQL and Powershell are the most common as they are 'native' to the system and do not create dependencies by having to maintain additional software; C# brings .NET version dependencies (sortof)....
I see that Python is quite popular as well as Perl, however my Perl knowledge is 'nil and Python looks fairly easy for what my requirements are. Are there any good reasons to use one or another language for writing automation scripts/processes?
Before scripting anything against mysql, you should leverage the mysql client utilities. That way, you do not find yourself reinventing the wheel.
As long as you have a good mastery over the mysql client utilities, whichever langauge you decide to program in for custom utilities is simply a matter of personal choice.
IMHO from a DBA perspective, it is best to perform basic shell scripting to call SQL scripts. Again, just a matter of personal choice.
Generally, whatever you're familiar with. Our shop works in PHP, so our MySQL automation scripts are in PHP as well.

General Questions about MySQL and MySQLite

I am going to be writing to a MySQLite database file, using Perl's DBD:SQLite module, and I wondering if it is possible for this file to be read by any distribution of MySQL? Is there a better way to create a simple MySQL database (using Perl)?
If it means anything, I'm only going to be using the database to store key-value pairs based on unique ID numbers for the keys. I tried BerkeleyDB but there is little support for it on Perl and I could not get it to work correctly in the past on certain versions of Windows.
Edit: I am aware that BerkeleyDB is a better way to do this, but when I was writing scripts for it, most of the methods have TODO, and I've had mysterious bugs on Windows Server 2003 using the same airtight code that ran for 2 weeks straight on my Win7 machine at home.
MySQL and SQLite are completely separate RDBMS systems. There is no such thing as MySQLite. To the best of my knowledge, MySQL cannot read SQLite databases.
If all you really want is a key-value store, perhaps look at Redis: http://code.google.com/p/redis/
I use Perl's DBI module which I can use to read databases using either MySQL or SQLite. All you need is the correct driver. In fact, if you write your program correctly, the backend database (either SQLite or MySql) is irrelevant. Your program will work with either one.
However, you can't use a SQLite database and then treat it as a MySQL database. They're two different creatures. Your program can be database agnostic, but once you chose a database, you can't switch back and forth. It'd be like opening an Oracle database as a MySQL database.
See This posting on Perl Monks for more info.
BerkeleyDB is well supported by perl. You have a choice between the older DB_File and the more fully featured BerkeleyDB module.
But there are tons of choices. If you don't want to have to run a separate server process, use DBI and DBD::SQLite or BerkeleyDB or any of the AnyDBM_File modules. For a simple server-based key-value store, there's redis or the older memcached.

Interacting with a Database from Scheme

i try to learn scheme and as a test project i wanted to create a very simple website with 1-2 database queries (MySQL preferred, but PostgreSQL would be ok, too).
I know it's not really schemes domain but i still want to see how far i can come.
Sadly, it seems i'm already stuck at using a database and googling for "scheme database" or any other combination including this words was (as expected considering the double meaning of scheme in this case) not very helpful.
Can you give me any hints on how to access a database from a scheme program?
I read something about scheme code interfacing a mysql client program to do that but i'd prefer something more direct.
Thanks.
GNU Guile already has a database interface that supports Postgres, MySQL and SQLite. It is
called Guile DBI. Other Scheme implementations you may try are: SISC (Can connect
to any JDBC compliant database, including MySQL) and Spark-Scheme (Can connect to any
ODBC compliant database, including MySQL and comes bundled with SQLite). Also note that most
Scheme implementations has some form of Foreign Function Interface that will help you
to write your own MySQL->Scheme Connector.

Need a tool to convert postgres database to mysql

I found the mysql migration toolkit which will migrate the tables.But is there something which will convert the functions as well.
Almost certainly not.
If your functions are in the SQL language only, it should probably be doable. But any of the many other languages supported by PostgreSQL (pl/pgsql, perl, python etc) are completely different, and contain much functionality that's simply not supported on MySQL.
most likely not. the stored procedure and function language differs greatly between postgresql and mysql. such an application would be costly to develop.
There are several data migration tools available on Google to convert database. I use dbload for example.