Test::mysqld - mysqld runner for tests
use DBI; use Test::mysqld; use Test::More; my $mysqld = Test::mysqld->new( my_cnf => { 'skip-networking' => '', # no TCP socket } ) or plan skip_all => $Test::mysqld::errstr; plan tests => XXX; my $dbh = DBI->connect( $mysqld->dsn(dbname => 'test'), );
Test::mysqld automatically setups a mysqld instance in a temporary directory, and destroys it when the perl script exits.
Test::mysqld
Create and run a mysqld instance. The instance is terminated when the returned object is being DESTROYed. If required programs (mysql_install_db and mysqld) were not found, the function returns undef and sets appropriate message to $Test::mysqld::errstr.
Returns directory under which the mysqld instance is being created. The property can be set as a parameter of the new function, in which case the directory will not be removed at exit.
new
If specified, uses a copy of the specified directory as the data directory of MySQL. "Mysql" database (which is used to store admistrative information) is automatically created if necessary by invoking mysql_install_db.
A hash containing the list of name=value pairs to be written into my.cnf. The property can be set as a parameter of the new function.
Path to mysql_install_db script or mysqld program bundled to the mysqld distribution. If not set, the program is automatically search by looking up $PATH and other prefixed directories.
mysql_install_db
mysqld
Builds and returns dsn by using given parameters (if any). Default username is 'root', and dbname is 'test'.
Returns process id of mysqld (or undef if not running).
Starts mysqld.
Stops mysqld.
Setups the mysqld instance.
Returns the contents of the mysqld log file.
Copyright (C) 2009 Cybozu Labs, Inc. Written by Kazuho Oku.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Test::mysqld, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::mysqld
CPAN shell
perl -MCPAN -e shell install Test::mysqld
For more information on module installation, please visit the detailed CPAN module installation guide.