Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I want to create an embedded MySQL database for running tests, but I'm not sure how to do it.

  • How do I initialize the database?
  • How do I run my create table statements?

I'm using Perl, so it needs to be done with a language and not a couple of commands.

share|improve this question

1 Answer 1

Here are the functions from the C/C++ API

  • mysql_library_init() : Should be called before any other MySQL function is called, preferably early in the main() function.
  • mysql_library_end() : Should be called before your program exits.
  • mysql_thread_init() : Should be called in each thread you create that accesses MySQL.
  • mysql_thread_end() : Should be called before calling pthread_exit()

Personally, I have searched high and low for the Perl equivalent of these C/C++ API calls that would open an embedded MySQL Server. Apparently, none exists for the Perl API.

Here is an excerpt from dev.mysql.com that verifies this:

The embedded MySQL server library makes it possible to run a full-featured MySQL server inside a client application. The main benefits are increased speed and more simple management for embedded applications.

The embedded server library is based on the client/server version of MySQL, which is written in C/C++. Consequently, the embedded server also is written in C/C++. There is no embedded server available in other languages.

You may have to manually trigger the start of mysql yourself with something like this:

@args = {"/sbin/service","mysql","status"};
$rc = 0xFFFF & system(@args);
if ( $rc != 0 ) {
    @args = {"/sbin/service","mysql","start"};
    system(@args) == 0 or die "mysql start failed : $?";
}
share|improve this answer
    
yeah I've only found brief reference to embedded mysql in DBD::mysql –  xenoterracide Jul 1 '11 at 18:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.