in reply to Re^3: Reading host from defaults file with DBD::mysql
in thread Reading host from defaults file with DBD::mysql

Actually, I think I've identified the problem. It appears it is working as long as there are NO SPACES in the setting lines in the MySQL defaults file. If there are spaces around the "=", the setting is not read.

So a defaults file containing:

[mysql] user=fred host=mydb.localdomain password=BANANA

works, but:

[mysql] user = fred host = mydb.localdomain password = BANANA

does not.

Replies are listed 'Best First'.
Re^5: Reading host from defaults file with DBD::mysql
by pryrt (Abbot) on Feb 01, 2019 at 15:28 UTC

    What module did you use for reading/parsing your INI file? Config::Tiny? Config::Simple? Config::INI? Something else? Or did you roll your own?

    For example, Config::Tiny handles spaces around the equals just fine:

    #!/usr/bin/perl -l use warnings; use strict; use Config::Tiny; my $ini_string = <<"EOINI"; a=nospace b = space [GROUP1] c=nospace d = space EOINI my $cfg = Config::Tiny->read_string($ini_string); use Data::Dumper; $Data::Dumper::Indent = 0; print Dumper $cfg; __END__ __OUTPUT__ $VAR1 = bless( {'_' => {'a' => 'nospace','b' => 'space'},'GROUP1' => { +'d' => 'space','c' => 'nospace'}}, 'Config::Tiny' );

    I don't have the other two installed, but Config::INI claims to handle spaces around the equals, and Config::Simple's claim of "whitespace support" implies to me that it might

      The file, as part of $dsn string, is passed to DBI->connect method. I failed to find in (top level) DBI & DBD::mysql sources a point where it would have been parsed.

        Sorry, I didn't notice the filename went into the $dsn -- I'm not a database expert, and didn't know it could go there. Digging into the code, it appears that it's parsed via the underlying c code, using mysql_options(sock, MYSQL_READ_DEFAULT_FILE, df);. The mysql-options documentation says that you use that option to get it to read from the given file... The option-files doc claims that "Leading and trailing spaces are automatically deleted from option names and values", which implies that spaces around the equal shouldn't matter. It may be that you've got a different version of mysql than the 8.0 reference manual my searches brought me to, or that the statement is misleading and spaces around the equal are bad.

        edit: fix "optoins" typo. Also, want to clarify: when I saw the anonymous "seriously" reply, I wanted something slightly more helpful than that. However, I was apparently confused into believing the parsing was something you had done externally to what you had quoted, rather than something that mysql handles internally. So instead of being helpful, I went in the wrong debug direction. Sorry.

Re^5: Reading host from defaults file with DBD::mysql
by Anonymous Monk on Feb 01, 2019 at 05:05 UTC

    Seriously? Are you sure you had not changed anything other than spaces around "=" in the mysql defaults file?