Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

[SOLVED-ISH]DBI Connection Fails with Access Denied on one version of Perl/DBD::MySQL and work on the other

by varneraa (Acolyte)
on May 29, 2020 at 05:29 UTC ( [id://11117445]=perlquestion: print w/replies, xml ) Need Help??

varneraa has asked for the wisdom of the Perl Monks concerning the following question:

EDIT: Solved-ish. Part of my problem appears to have been that I only added the bin area of the MySQL version to my path before calling cpanm to build DBD::mysql. Once I added the lib area of the mysql version as well and rebuilt 4.043 DBD::mysql I now have a working version. However, this seems super fragile. 4.050 DBD::mysql still doesn't work and DBD::MariaDB still doesn't work. This was all with the 5.26.1 version of Perl. I am going to give this a try on my original repo with 5.30.2 and see if it works. At least there is a little light at the end of this tunnel. I'd still love to figure out the right way to do all of this.

TLDR:
PROBLEM: Access denied for user 'USER_REPLACED'@'IP_REPLACED' (using password: YES) error 1045 recorded: Access denied for user 'USER_REPLACED'@'IP_REPLACED' (using password: YES)
WORKS: DBI 1.639-nothread w/ 5.26.1 perl w/ DBD::mysql 4.043 from standard install path in controlled linux environment connects to MariaDB 10.2 in internal dbaas cloud
NO DICE: DBI 1.643-nothread w/ 5.30.2 Perl w/ DBD::mysql 4.050 from perlbrew install path in controlled linux environment fails to connect to MariaDB 10.2 in internal dbaas cloud
NO DICE: DBI 1.616-nothread w/ 5.14.1 Perl w/ DBD::mysql 4.020 from standard install path in controlled linux environment also fails to connect to MariaDB 10.2 in internal dbaas cloud

Same script, same host, repeatable, but version dependent(maybe?) failures. So the question remains, how can I debug and fix this? I've many other posts on this error, but they are usually a config issue with the DB or a bad username/password. If this failed across the board I would think I was in the same boat, but the same code works on a specific perl install.

Full fat version:
I'm stumped. I work in a fairly restricted computing environment with pre-installed Perl and libraries. Several years ago now I picked up perlbrew as a way to allow me to develop tools that used CPAN libraries not preinstalled with the available Perl versions on our systems.

Getting DBD::MySQL was a pain, since it requires mysql_config availability, which is not part of the normal path in this environment. Thanks to some other help I was able to get it installed and was able to get my perlbrewed script to connect to a MySQL db I use internally. Yay! Not so much.

This new DB I am working on uses an internal dbaas mariaDB instance: MYSQL (MariaDB 10.2). With the stock version of Perl in our environment 5.14.1 I fail to connect, with a second standard install Perl version 5.26.1 I am able to connect, and finally, with my PerlBrewed 5.30.2 I am unable to connect.

In each case, I am using an identical script and just changing the Perl version that is installed to isolate variables in my testing.

#!/STANDARDINSTALLPATHTHATWORKS/5.26.1/bin/perl use strict; use warnings; use Data::Dumper; use DBI; my $database = "DB_REMOVED"; my $hostname = "HOST_REMOVED"; my $port = "PORT_REMOVED"; my $user = "USER_REMOVED"; my $pass = "PASS_REMOVED"; my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; DBI->trace(2); my $dbh = DBI->connect($dsn, $user, $pass) or die("Failed to connect t +o DB: $!");
I found DBI's trace function, but it hasn't told me anything new, but here are the outputs first from the failing one(perlbrew) and then from the passing one:
DBI 1.643-nothread default trace level set to 0x0/2 (pid 87123 pi +0) at dbtest line 20 -> DBI->connect(DBI:mysql:database=DB_REPLACED;host=HOSTNAME_REPLA +CED;port=PORT_REPLACED, USER_REPLACED, ****, HASH(0x9094f0)) -> DBI->install_driver(mysql) for linux perl=5.030002 pid=87123 ru +id=ID_REPLACED euid=ID_REPLACED install_driver: DBD::mysql version 4.050 loaded from PRIVATEPER +LBREWINSTALL/extlib/lib/perl5/x86_64-linux/DBD/mysql.pm <- install_driver= DBI::dr=HASH(0xc91698) !! The warn '0' was CLEARED by call to connect method -> connect for DBD::mysql::dr (DBI::dr=HASH(0xc91698)~0xce2e38 'da +tabase=DB_REPLACED;host=HOSTNAME_REPLACED;port=PORT_REPLACED' 'USER_R +EPLACED' **** HASH(0xb558d0)) imp_dbh->connect: dsn = database=DB_REPLACED;host=HOSTNAME_REPLACED;po +rt=PORT_REPLACED, uid = USER_REPLACED, pwd = PASSWORD_REPLACED imp_dbh->my_login : dbname = DB_REPLACED, uid = USER_REPLACED, pwd = P +ASSWORD_REPLACED,host = HOSTNAME_REPLACED, port = PORT_REPLACED imp_dbh->mysql_dr_connect: host = |HOSTNAME_REPLACED|, port = PORT_REP +LACED, uid = USER_REPLACED, pwd = PASSWORD_REPLACED imp_dbh->bind_type_guessing: 0 imp_dbh->use_server_side_prepare: 0 imp_dbh->disable_fallback_for_server_prepare: 0 imp_dbh->mysql_dr_connect: client_flags = 2 imp_dbh->mysql_dr_connect: <- --> do_error Access denied for user 'USER_REPLACED'@'IP_REPLACED' (using password: +YES) error 1045 recorded: Access denied for user 'USER_REPLACED'@'IP_ +REPLACED' (using password: YES) <-- do_error -> DESTROY for DBD::mysql::db (DBI::db=HASH(0xce33f0)~INNER) DESTROY for DBI::db=HASH(0xce33f0) ignored - handle not initi +alised ERROR: 1045 'Access denied for user 'USER_REPLACED'@'IP_REPLACE +D' (using password: YES)' (err#0) <- DESTROY= ( undef ) [1 items] at mysql.pm line 163 !! ERROR: 1045 'Access denied for user 'USER_REPLACED'@'IP_REPLACE +D' (using password: YES)' (err#0) <- connect= ( undef ) [1 items] at DBI.pm line 679 -> $DBI::errstr (&) FETCH from lasth=HASH <- $DBI::errstr= 'Access denied for user 'USER_REPLACED'@'IP_REPLA +CED' (using password: YES)' DBI connect('database=DB_REPLACED;host=HOSTNAME_REPLACED;port=P +ORT_REPLACED','USER_REPLACED',...) failed: Access denied for user 'US +ER_REPLACED'@'IP_REPLACED' (using password: YES) DBI connect('database=DB_REPLACED;host=HOSTNAME_REPLACED;port=PORT_REP +LACED','USER_REPLACED',...) failed: Access denied for user 'USER_REPL +ACED'@'IP_REPLACED' (using password: YES) at PRIVATEPERLBREWINSTALL/. +bin/dbtest line 21. -- DBI::END ($@: , $!: ) !! The ERROR '1045' was CLEARED by call to disconnect_all method -> disconnect_all for DBD::mysql::dr (DBI::dr=HASH(0xc91698)~0xce2 +e38) <- disconnect_all= ( ) [0 items] (not implemented) at DBI.pm line +758 ! -> DESTROY in DBD::_::common for DBD::mysql::dr (DBI::dr=HASH(0xce +2e38)~INNER) ! <- DESTROY= ( undef ) [1 items] during global destruction
Passing one:
DBI 1.639-nothread default trace level set to 0x0/2 (pid 87340 pi +0) at old_dbtest line 20 -> DBI->connect(DBI:mysql:database=DB_REPLACED;host=HOSTNAME_REPLA +CED;port=PORT_REPLACED, USER_REPLACED, ****) -> DBI->install_driver(mysql) for linux perl=5.026001 pid=87340 ru +id=ID_REPLACED euid=ID_REPLACED install_driver: DBD::mysql version 4.043 loaded from STANDARDEN +VINSTALLAREA/x86_64-linux/DBD/mysql.pm <- install_driver= DBI::dr=HASH(0x974b28) !! The warn '0' was CLEARED by call to connect method -> connect for DBD::mysql::dr (DBI::dr=HASH(0x974b28)~0x9ac9f8 'da +tabase=DB_REPLACED;host=HOSTNAME_REPLACED;port=PORT_REPLACED' 'USER_R +EPLACED' **** HASH(0x83f588)) imp_dbh->connect: dsn = database=DB_REPLACED;host=HOSTNAME_REPLACED;po +rt=PORT_REPLACED, uid = USER_REPLACED, pwd = PASSWORD_REPLACED imp_dbh->my_login : dbname = DB_REPLACED, uid = USER_REPLACED, pwd = P +ASSWORD_REPLACED,host = HOSTNAME_REPLACED, port = PORT_REPLACED imp_dbh->mysql_dr_connect: host = |HOSTNAME_REPLACED|, port = PORT_REP +LACED, uid = USER_REPLACED, pwd = PASSWORD_REPLACED imp_dbh->bind_type_guessing: 0 imp_dbh->use_server_side_prepare: 0 imp_dbh->disable_fallback_for_server_prepare: 0 imp_dbh->mysql_dr_connect: client_flags = 2 imp_dbh->mysql_dr_connect: <- <- connect= ( DBI::db=HASH(0x9acf80) +) [1 items] at DBI.pm line 676 -> STORE for DBD::mysql::db (DBI::db=HASH(0x9ad1a8)~INNER 'PrintEr +ror' 1) <- STORE= ( 1 ) [1 items] at DBI.pm line 728 -> STORE for DBD::mysql::db (DBI::db=HASH(0x9ad1a8)~INNER 'AutoCom +mit' 1) <- STORE= ( 1 ) [1 items] at DBI.pm line 728 -> STORE for DBD::mysql::db (DBI::db=HASH(0x9ad1a8)~INNER 'Usernam +e' 'USER_REPLACED') <- STORE= ( 1 ) [1 items] at DBI.pm line 731 -> STORE for DBD::mysql::db (DBI::db=HASH(0x9ad1a8)~INNER 'mysql_c +onn_attrs' HASH(0x9ad160)) $h->{'mysql_conn_attrs'}=HASH(0x9ad160) ignored for invalid driver-spe +cific attribute <- STORE= ( '' ) [1 items] at DBI.pm line 731 -> connected in DBD::_::db for DBD::mysql::db (DBI::db=HASH(0x9acf +80)~0x9ad1a8 'DBI:mysql:database=DB_REPLACED;host=HOSTNAME_REPLACED;p +ort=PORT_REPLACED' 'USER_REPLACED' ****) <- connected= ( undef ) [1 items] at DBI.pm line 738 <- connect= DBI::db=HASH(0x9acf80) -> STORE for DBD::mysql::db (DBI::db=HASH(0x9ad1a8)~INNER 'dbi_con +nect_closure' CODE(0x9ac890)) <- STORE= ( 1 ) [1 items] at DBI.pm line 747 Died at bin/old_dbtest line 24. -> DESTROY for DBD::mysql::db (DBI::db=HASH(0x9ad1a8)~INNER) imp_dbh->pmysql: 9c7aa0 <- DESTROY= ( undef ) [1 items] at old_dbtest line 24 -- DBI::END ($@: , $!: ) -> disconnect_all for DBD::mysql::dr (DBI::dr=HASH(0x974b28)~0x9ac +9f8) <- disconnect_all= ( ) [0 items] (not implemented) at DBI.pm line +755 ! -> DESTROY in DBD::_::common for DBD::mysql::dr (DBI::dr=HASH(0x9a +c9f8)~INNER) ! <- DESTROY= ( undef ) [1 items] during global destruction
  • Comment on [SOLVED-ISH]DBI Connection Fails with Access Denied on one version of Perl/DBD::MySQL and work on the other
  • Select or Download Code

Replies are listed 'Best First'.
Re: DBI Connection Fails with Access Denied on one version of Perl/DBD::MySQL and work on the other
by hippo (Bishop) on May 29, 2020 at 09:42 UTC

    These sorts of problems are always intensely frustrating and you have my sympathy. While there's nothing obviously wrong (to me) in your well-written post I can only offer these 3 possibilities. Hopefully one will be of some help.

    Firstly, I can't help but notice that your 3 client environments change 3 things each time between them: perl version, DBI version and DBD::mysql version. This is confounding so it would be great to try to fix it and only change one thing. Probably the easiest is to modify the DBI and DBD::mysql versions in your perlbrew install to be the same as the currently working environment. If you can connect with that then it's a module version issue and you can look into the changelogs, etc. If you can't then it's either a perl version issue (unlikely but not impossible) or an environment issue.

    Secondly, and orthogonally, there is a DBD::MariaDB module available. It is for the most part interchangeable with DBD::mysql but since you say you have a MariaDB server, it's probably worth investigating in case it makes the problem vanish in a simple way.

    Finally, consider the possibility that the problem might be related to something on the server side. I'm sure you are aware that MariaDB auth may be restricted to certain client IP addresses and there could be a myriad of other reasons why even with seemingly identical connection profiles the server rejects some connection attempts. Try connecting using a completely different client if you can to see if it is some environmental concern which is the underlying cause. It would also help to have a word with the DBA about this as they should be able to say at once if they are using some particular restriction which might explain what you are seeing.

    Good luck with your investigations.

      EDIT: Solved-ish. Part of my problem appears to have been that I only added the bin area of the MySQL version to my path before calling cpanm. Once I added the lib area of the mysql version as well and rebuilt 4.043 DBD::mysql I now have a working version. However, this seems super fragile. 4.050 DBD::mysql doesn't work and MariaDB still doesn't work. This was all with the 5.26.1 version of Perl. I am going to give this a try on my original repo with 5.30.2 and see if it works. At least there is a little light at the end of this tunnel.


      Thanks for the reply. I was having the same thoughts about the versions, just before checking for replies this morning I took the time to sync my perlbrew install with the working standard install and as to be expected, it still does not work...

      Version Matching: No luck. The only variable left there is probably the library version of MySQL used for building DBD::MySQL. I'm not completely sure how to check that for the standard install Perl. I had to add a version to my path before building the ones in perlbrew. I was using 5.1.46-64, but DBD::MariaDB failed to install with that so I found 5.7.16, which allowed the install to complete. However, both DBD::mysql and DBD::MariaDB both hit the 1045 error.

      DBD::MariaDB: No luck. Got it to install, but I'm seeing the same 1045 error

      For a final check, I pointed this at another DB I work with(5.6.34 MySQL) and the perlbrew version works... I'm really annoyed this dbaas service doesn't just offer MySQL...

      I'll have to see if I can get in touch with anyone in IT about this and maybe play around with pointing to other MySQL versions for the DBD builds.
Re: DBI Connection Fails with Access Denied on one version of Perl/DBD::MySQL and work on the other
by derby (Abbot) on May 29, 2020 at 11:01 UTC

    This is a nice tough one. Out of curiosity, does your db password have any special characters in it? If so, you may want to use single quotes when setting it

    my $pass = 'PASS_REMOVED';

    Also, it's probably not going to shed any light but instead of $! when failing, use $DBI::errstr

    Good Luck!

    -derby
      Good point, I did see another post talking about a similar issue with special characters, so I did check for that. The password is alphanumeric.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11117445]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-18 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found