I think that you are mixing up a couple of things.
There is a dataset name ($dsn) which is a mySQL database on a particular host name and port number. That has to exist or you are going "nowhere"!
If the $dsn exists, then you can attempt to connect to it. This is where the user name and passwords are required.
my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"
|| die "DB data set name failed $!\n";
#
# second step #
#
my $dbh = DBI->connect($dsn, $user, $password)
|| die "DB connect failed $!\n";
The $dsn and the final connected handle, $dbh are very different things.
|