http://qs321.pair.com?node_id=879840

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

Hello How do you connect to a mysql database as an anonymous user with perl? The following did not work:
my $username = "anonymous"; my $password = "yes"; our $sql_database = "xxxx"; our $sql_host = "xx"; our $sql_port = "3306"; my $db = DBI->connect("DBI:mysql:database=$sql_database;host=$sql_host +;port=$sql_port", $username, $password, {'RaiseError' => 1});
The error message was access denied for anonymous with password yes.

thanks a lot

Replies are listed 'Best First'.
Re: how to connect to mysql as anonymous user with perl
by roboticus (Chancellor) on Dec 30, 2010 at 18:09 UTC

    Perhaps you should create the user 'anonymous' with password 'yes' on the database.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: how to connect to mysql as anonymous user with perl
by oko1 (Deacon) on Dec 30, 2010 at 18:32 UTC

    You may be confusing something like FTP - where anonymous users log in with 'anonymous' as the username and some random string (usually, an email address) - with MySQL, where anonymous users log in with 'guest' (usually) as the username and no password. It's a different scenario overall.

    Of course, you could follow the advice you got from roboticus if you actually want to have a user named 'anonymous' with a password of 'yes' - but that would create an expectation failure. The point of default usernames and passwords is that most people know what they are in a given situation and thus don't have to ask anyone. No one is going to be able to guess your username and password - which means that "anonymous/yes" is no different from "fizzlegig/Af5&%#g!dRqqq" (i.e., a non-anonymous username/password pair.)

    -- 
    Education is not the filling of a pail, but the lighting of a fire.
     -- W. B. Yeats
Re: how to connect to mysql as anonymous user with perl
by PeterPeiGuo (Hermit) on Dec 30, 2010 at 18:33 UTC

    If this is a vanilla installation of mysql, the user name for anonymous user is "" (empty string) - that's the reason why it was called an anonymous user, and the password is also "".

    Peter (Guo) Pei

      Invoking MySQL without a username or a password defaults to the current login and no password:

      perl -MDBI -we'my $dbh=DBI->connect("dbi:mysql:","","")' DBI connect('','',...) failed: Access denied for user 'ben'@'localhost +' (using password: NO) at -e line 1

      ...and there doesn't seem to be any way to force it to accept a blank username, either:

      mysql --user="" --password="" ERROR 1045 (28000): Access denied for user 'ben'@'localhost' (using pa +ssword: NO)
      -- 
      Education is not the filling of a pail, but the lighting of a fire.
       -- W. B. Yeats