my $host = "localhost"; my $port = "3306"; my $user = "root"; my $pass = "111"; my $db_name = "test"; my $db_user = "test"; my $db_pass = "test"; my $dsn = "dbi:mysql::$host:$port"; my $dbh = DBI->connect($dsn, $user, $pass) or die "Unable to connect: $DBI::errstr\n"; $dbh->do("CREATE DATABASE $db_name"); $dbh->do("CREATE USER $db_user\@$host");
$dbh->do("GRANT ALL ON $db_name.* TO $db_user\@$host IDENTIFIED BY '$db_pass'");
$dbh->disconnect();