in reply to Reading host from defaults file with DBD::mysql

It's hard to tell without input data .

Your best bet is to run this under the perl debugger:

perl -d <your code file>
and step through (s command in debugger), to see what path it takes, and examine variables as it steps through (x command in the debugger).

                As a computer, I find your faith in technology amusing.

Replies are listed 'Best First'.
Re^2: Reading host from defaults file with DBD::mysql
by Llew_Llaw_Gyffes (Scribe) on Jan 30, 2019 at 13:44 UTC

    Oh, I've traced through my code and I know that it's doing what it should and reading the correct section of the defaults file. The problem is that DBD::mysql does not appear to be passing along the host specification along with the username and password, and I'm wondering whether I have missed something in my usage. The documentation leads me to believe that it SHOULD be working, but it isn't.

      Have you gone through Basic debugging checklist? Sounds like you've now done part (using the debugger), but maybe not everything: Does your $opts{defaults} really contain what you think it does when it enters the sub you showed? If not, then the problem lies outside of what you've shown. If it does contain what you think it should, then give us a security-redacted version of $opt{defaults}, because we cannot debug your logic in that sub without knowing what's there. See also SSCCE, How to ask better questions using Test::More and sample data, and How do I change/delete my post?


      edit: add "everything": I had intended the "but maybe not: ..." to be one logical thought, separate from "you've now done part"... but when re-reading, it looked more like I was saying OP hadn't done even the running-the-debugger, which was not what I meant. sorry. /edit

        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.