Вопрос

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?

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top