my $my_cnf = 'path_to_somewhere_safe/my_cnf.cnf'; my $dsn = "DBI:mysql:;" . "mysql_read_default_file=$my_cnf"; my $dbh = DBI->connect( $dsn, undef, undef, {RaiseError => 1} ) or die "DBI::errstr: $DBI::errstr";