MySQL::Hi - Credentials for MySQL/MariaDB from config files
my $hi = MySQL::Hi->new( user => $user, config => '/path/to/config.conf' ); # Command line options my @options = $hi->get_options( $db, $mode ); # DSN my ( $dsn, $user, $password ) = $hi->get_dsn();
The module to read config with credentials for MySQL/MariaDB conection.
It does NOT do any MySQL/MariaDB connections, it is ONLY needed to read a config file and return credentials, comannd line options for MySQL/MariaDB client, or DSN for DBD::mysql driver.
Creates an object.
Username to connect to DB. If omitted, curent username is taken.
Path to a cofigfile. By default it searces for the file mysqlhi.conf in user's home directory. See "Config file" in mysqlhi for config file format.
NOTE: I only tested it on Debian and Ubuntu. I have not tested it on other operating systems. As long as it uses File::HomeDir it should, in theory, work on other OSes too. If it does not, your patches are welcome.
Returns a list of parameters which can be directly used for the command exec:
exec
exec 'mysql', $hi->get_options( $db, $mode );
NOTE: exec should be used with multiple parameters. This will make sure that all parameters are passed to the command correctly, and it will run mysql directly without sh -c predicate. As a useful side effect, in the list of processes your MySQL/MariaDB client will not show password.
mysql
sh -c
The method accepts two parameters: $db (database name) and $mode (Optional, used to specify credentials for a certain mod). See mysqlhi for information about modes.
$db
$mode
Accepts the same parameter as get_credentials, Returns DSN, username and password which can be used directly in DBI-connect()>:
get_credentials
DBI-
DBI->conect( $hi->get_dsn( $db, $mode ) )
With no param it return all parsed credentials from the config file.
If $db and $mode are provided, return a hashref with credentials for this databade in this mode.
Not reported... Yet...
mysqlhi
Andrei Pratasavitski <andrei.protasovitski@gmail.com>
This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install MySQL::Hi, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MySQL::Hi
CPAN shell
perl -MCPAN -e shell install MySQL::Hi
For more information on module installation, please visit the detailed CPAN module installation guide.