http://www.perlmonks.org?node_id=1053482

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

How can I do the thing in the title?

I've been googleing it for a lot of time but it seems that there's no way to access a database where no password has been set.

In example I use this form to create a db:

 $drh->func("createdb", $database, $host, $mySqlUser, $mySqlPass, 'admin');

and it works.

.

but what about if I don't have user and password for my mysql?

This one for sure don't work...

 $drh->func("createdb", $database, $host, 'admin');

Replies are listed 'Best First'.
Re: Using DB->connect for mysql db without password
by rnewsham (Curate) on Sep 11, 2013 at 13:54 UTC

    Having databases without passwords is a bad idea, but if you really must do it the following code works for me.

    my $database = 'test'; my $dbh = DBI->connect("DBI:mysql:$database",undef,undef,{ RaiseError +=> 1 });
Re: Using DB->connect for mysql db without password
by hdb (Monsignor) on Sep 11, 2013 at 13:00 UTC

    If you are the one to create the database, why don't you just set a user and password?

Re: Using DB->connect for mysql db without password
by jfroebe (Parson) on Sep 11, 2013 at 13:06 UTC

    You should always have a password set for any logins to a dbms even if it is just you accessing the database.

    Jason L. Froebe

    Blog, Tech Blog

      I don't want to appear stupid... :D

      My problem is that I'm creating a software that does some analysis based on the use of a MySQL database. Now, I installed this program on a machine where I seen that mysql can be accessed without any pwd and usr. So I was wondering: "what if the user didn't set these two parameters?".

      I'm going crazy searching for an answer. I think now that this is not a possible situation with PERL DBI... is it true?

        Have you tried using undef or '' for the username and/or password?

        What software are you using, exactly? You don't seem to call DBI->connect, but rather a connect method on a different object. What kind of object is it?

        Usually connecting to mysql without user name and without password only works if you don't specify a host name either (not even localhost), then local domain sockets are used, and the identity of the system user is used.

Re: Using DB->connect for mysql db without password
by karlgoethebier (Abbot) on Sep 11, 2013 at 18:54 UTC

    Please, give your mySQL database a password and the appropriate permissions, it's best practice.

    This ugly "no password approach" at basic setup is IMHO one of the sickest quirks of mySQL.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»