Best way to populate a db from an installer script

I’m writing an Perl installer for my own custom software, and have looked at many examples. Most of them end by displaying a URL for the sysadmin to click on. Clicking on the URL takes the person to the rest of the installation, which includes populating the database, and any other unsundries.

I’d prefer to skip this step, as the only way I can make money at this business is through automating every tedious process I can. :slight_smile:

My first thought was to insert this into my script_XXX_install function:

my $install_script = $opts->{‘dir’} . ‘/install.sql’;
my $cmd = “/usr/bin/mysql --port=3306 --database=$dbname --host=$dbhost --user=$dbuser --password=$dbpass < $install_script”;
my $error_code = system($cmd);

So inelegant. Hard-wired path to mysql, for instance. I’m thinking there must be a function built into the API to accomplish this. E.g., there’s a create_script_database() function which is the first thing my script calls:

local $err = &create_script_database($d, $opts->{‘db’});

My problem is, though I have the URL for the excellent documentation on writing script installers:,script_installers/

However, I don’t know of an API document describing the functions used by the scdript installers – e.g., create_script_database() and all the other built-in functions.

A pointer to a document for the API would be appreciated.


Post edited by: emduck, at: 2008/09/23 18:03<br><br>Post edited by: emduck, at: 2008/09/23 18:06

Hi Emily,

There is actually just such a function in Webmin, for running a file of SQL. You can call it with code like :

($exitstatus, $out) = &mysql::execute_sql_file($dbname, $opts->{‘dir’}.’/install.sql’, $dbuser, $dbpass);
if ($exitstatus != 0) {
return (-1, "Setup SQL failed"«»);

Some of these inter-module API calls aren’t well documented yet, but I am working on it…