简体   繁体   English

Perl DBI无需密码即可连接到mysql数据库

[英]perl DBI connect to mysql database without password

I would like to use DBI to connect to a mysql database as user mysql, but without password. 我想使用DBI以mysql用户身份连接到mysql数据库,但没有密码。 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: 我的Perl代码:

#!/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. 因此, DBI->connect的第三个参数是密码。 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. 我尝试了各种方法作为第三个参数: NULLnull''' '等,但是每次将其解释为密码时。 Any ideas? 有任何想法吗?

just use undef : 只需使用undef

$dbh = DBI->connect("DBI:mysql:perltest","mysql",undef,{ RaiseError => 1 });

UPD. UPD。 btw, this fiddle is probably helpful explanation of how perl operates with all this null/0/undefined stuff. 顺便说一句, 这个小提琴可能是有关perl如何使用所有null / 0 / undefined东西的有用说明。 Got original code from here 这里得到原始代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM