Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Using DB->connect for mysql db without password

by angeloulivieri (Novice)
on Sep 11, 2013 at 12:34 UTC ( #1053482=perlquestion: print w/replies, xml ) Need Help??
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 (Chaplain) 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 (Prior) 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 (Prior) 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»

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1053482]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2017-06-29 16:07 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (672 votes). Check out past polls.