以前写DBI时候,都是形式如下:
# Link Informations And New Class
my $dsn = "dbi:$DATABASE{driver_name}:database=$DATABASE{db_name};
hostname=$DATABASE{db_host};socket=$DATABASE{db_sock};
port=$DATABASE{db_port}";
$dbh = DBI->connect($dsn, $DATABASE{db_user}, $DATABASE{db_pass},
{'RaiseError' => 1});
我发现对于一台服务器多种mysql的情况:这种调用socket的方式发生了变化,具体发生变化的DBI版本是多少,我无法考究,但是现在变更为:
my $dsn = "dbi:$DATABASE{driver_name}:database=$DATABASE{db_name};关于perl介绍中还有一块比较使用使用文件方式调用DBI接口:
hostname=$DATABASE{db_host};mysql_socket=$DATABASE{db_sock};
port=$DATABASE{db_port}";
my $dbh = DBI->connect($dsn, $DATABASE{db_user}, $DATABASE{db_pass},
{'RaiseError' => 1});
- mysql_read_default_file
These options can be used to read a config file like /etc/my.cnf or ~/.my.cnf. By default MySQL's C client library doesn't use any config files unlike the client programs (mysql, mysqladmin, ...) that do, but outside of the C client library. Thus you need to explicitly request reading a config file, as in
$dsn = "DBI:mysql:test;mysql_read_default_file=/home/joe/my.cnf";
$dbh = DBI->connect($dsn, $user, $password)
使用my.cnf文件的方式可以减少很多的麻烦。 :)