关于DBI的一点忽略的东西

以前写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};
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});
关于perl介绍中还有一块比较使用使用文件方式调用DBI接口:
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文件的方式可以减少很多的麻烦。 :)
 

Monthly Archives

Pages

Powered by Movable Type 7.7.2

About this Entry

This page contains a single entry by Cnangel published on October 21, 2007 9:56 PM.

XP自带的功能强大的搜索工具 was the previous entry in this blog.

批量查询IP引起的警示 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.