in reply to MariaDB : read credentials from file fails (via dsn option mariadb_read_default_file)

It seems to work for me, but the syntax of the config file is different:
[client] user=testuser;password=apass
Update: This is not true. See below for what's going on and how to really fix it.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
  • Comment on Re: MariaDB : read credentials from file fails (via dsn option mariadb_read_default_file)
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: MariaDB : read credentials from file fails (via dsn option mariadb_read_default_file)
by bliako (Abbot) on Nov 06, 2023 at 16:59 UTC

    I was away from the computer over the weekend while I saw your answer and thought Doh! but I am trying it out now and it fails as it reads the username till the end of line i.e. it includes the password as part of the username. My MariaDB version is 10.8.8 in linux.

      You are right, of course. I'm sorry for the confusion.

      But I think I've found the solution. The format of the file is OK with a newline, the problem is the invocation of the connect method: if you specify an empty string for the password, it has precedence over the one specified in the config. You need to specify undef for the password to get it replaced by the configuration value.

      my @dsns = ( $dsn, '', # username is read from file undef, # password is read from file!! {RaiseError => 1, PrintError => 1} );
      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        Thank you choroba++ your solution works! And it makes sense too.

        Thank you choroba++ your solution works! And it makes sense too.