just use undef
:
$dbh = DBI->connect("DBI:mysql:perltest","mysql",undef,{ RaiseError => 1 });
UPD. btw, this fiddle is probably helpful explanation of how perl operates with all this null/0/undefined stuff. Got original code from here
Question
I would like to use DBI to connect to a mysql database as user mysql, but without password. Is this possible?
Example:
#create database, grant access to mysql
mysql -e 'create database perltest; grant all on perltest.* to mysql@localhost'
my perl code:
#!/usr/bin/perl -w
use DBI;
$dbh = DBI->connect('dbi:mysql:perltest','mysql', NULL)
or die "Connection Error: $DBI::errstr\n";
So the third argument for DBI->connect
is the password. In all examples I have seen, a password is used. I tried various things as the third argument: NULL
, null
, ''
, ' '
etc., but every time it is interpreted as a password. Any ideas?
Solution
just use undef
:
$dbh = DBI->connect("DBI:mysql:perltest","mysql",undef,{ RaiseError => 1 });
UPD. btw, this fiddle is probably helpful explanation of how perl operates with all this null/0/undefined stuff. Got original code from here