use --login-path=local in perl DBD::mysql -


mysql supports passwordless login using stored local authentication credentials in file named .mylogin.cnf (see here more details).

for example:

mysql --login-path=local 

my questions is: how in perl using dbd::mysql?

dbd::mysql uses mysql c api, doesn't appear support login paths. alternative, can use option file , mysql_read_default_file , mysql_read_default_group options in connect call:

use strict; use warnings 'all';  use dbi;  $dsn = 'dbi:mysql:' .           ';mysql_read_default_group=local' .           ';mysql_read_default_file=/path/to/config';  $dbh = dbi->connect($dsn, undef, undef, {     printerror => 0,     raiseerror => 1 }); 

your option file should this:

[local] host     = localhost database = foo user     = myuser password = mypassword  [remote] host     = remote.example.com database = foo user     = myuser password = mypassword 

note unlike .mylogin.cnf (the file used --login-path), regular option files not encrypted. isn't big of problem might sound. main benefit of encryption prevents accidentally exposing credentials, e.g. when viewing file, doesn't provide unbreakable security. can still protect option file making sure it's not world-readable, excluding version control, etc.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -