开始看了一下DBD::mysql的Doc,看网页太长就没有细看,直接试了你给的 代码, 不行, 刚又仔细看了一下。 唉呀,我了个曹,哈哈:-P 。 根据描述下面的描述,hostname和port是要用":"连 在一起的,并且要“together”, *不要有"port="*,去掉 你帖的代码中的"port=", 然后,就可以通过apache连接了。谢谢啊!
Should the MySQL server be running on a non-standard port number, you may explicitly state the port number to connect to in the |hostname| argument, by concatenating the /hostname/ and /port number/***together* separated by a colon ( |:| ) character or by using the |port| argument. 明天再试着对数据库进行一下SELECT,希望不要出问题。 谢谢各路大神们热心回复、帮助和建议。再次祝大家归途顺利,提前给大家拜个早年。 *还想学习下夏凯提到的chroot,和“/”,这里的“/”,是apache配置文件里 的 DocumentRoot吗?我通过apache 来print `ls /`,结果打印出来的是系统的根目录 下的东西。 怎样才能让"apache"不chroot呢?还有没有其它的解决方案呢? 继续谢谢哈:-) Haiyan* On 02/01/2013 07:21 PM, wd wrote: > 哎呦我了个曹,我贴的你没看吗? > > $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; > > $dbh = DBI->connect($dsn, $user, $password); > > > http://search.cpan.org/~capttofu/DBD-mysql-4.022/lib/DBD/mysql.pm > <http://search.cpan.org/%7Ecapttofu/DBD-mysql-4.022/lib/DBD/mysql.pm> > > > > 2013/2/1 Haiyan Lin <[email protected] <mailto:[email protected]>> > > 代码如下, > > #!/usr/bin/perl > use DBI; > my $dbh = > > DBI->connect("dbi:mysql:host=localhost:datase=seedBase:mysql_socket=/tmp/mysql.sock",'user','password', > {'RaiseError' => 1}) or die $! ; > > print "Content-type: text/plain\n\n"; > print "mod_perl 2.0 rocks! \n"; > > > 错误是: > > [Fri Feb 01 16:42:11 2013] [error] DBI > > connect('host=localhost:database=seedBase:mysql_socket=/tmp/mysql.sock','apache',...) > failed: Can't connect to local MySQL server through socket > '/tmp/mysql.sock' (2) at /var/www/perl/rock.pl <http://rock.pl> > line 4\n > > > > > > > > > On 01/30/2013 10:09 PM, wd wrote: >> 还是一样是什么意思?还是报下面这个错误?贴你的代码和错误看看 >> Can't connect to local MySQL server through socket '/tmp/mysql.sock' >> >> >> 2013/1/30 Haiyan Lin <[email protected] >> <mailto:[email protected]>> >> >> 试过port=3306,但还是一样,防火墙的3306是开着的 >> >> >> On 01/30/2013 11:00 AM, wd wrote: >>> $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; >>> >>> $dbh = DBI->connect($dsn, $user, $password); >>> >>> >>> http://search.cpan.org/~capttofu/DBD-mysql-4.022/lib/DBD/mysql.pm >>> <http://search.cpan.org/%7Ecapttofu/DBD-mysql-4.022/lib/DBD/mysql.pm> >>> >>> >>> 2013/1/30 Haiyan Lin <[email protected] >>> <mailto:[email protected]>> >>> >>> 用TCP端口连,要怎么操作啊 >>> >>> >>> >>> On 01/30/2013 10:26 AM, wd wrote: >>>> 呃。。为啥一定要用 socket 连接呢?。。。 >>>> 通过 tcp 端口不也挺好么。。 >>>> >>>> >>>> 2013/1/30 夏凯 <[email protected] >>>> <mailto:[email protected]>> >>>> >>>> On 2013年01月30日 10:06, Haiyan Lin wrote: >>>> >>>> 怎么打印啊 >>>> >>>> print join "\n", (`ls /`) >>>> >>>> 吗? >>>> >>>> 应该这样就可以了,不过最好用 File::Spec来看下/下面 >>>> 的文件, 然后根据这个确 认下是被chroot到哪个目录, >>>> 再把mysql的 sock改到那个目录下,就能连接了。 >>>> 比如apache把/给chroot到/data,那么 你在apache访问 >>>> /tmp /mysql.sock实际上是 访问磁盘上的/data /tmp >>>> /mysql.sock。 >>>> >>>> 或者直接用-e /tmp/mysql.sock看下文件是否存在,这样 >>>> 可以确认是不是被chroot了。 >>>> >>>> >>>> -- >>>> 您收到此邮件是因为您订阅了 Google 网上论坛的 >>>> “PerlChina Mongers 讨论组”论坛。 >>>> 要退订此论坛并停止接收此论坛 的电子邮件,请发送电子 >>>> 邮件到 [email protected] >>>> <mailto:perlchina%[email protected]>。 >>>> 要向此网上论坛发帖,请发送电 子邮件至 >>>> [email protected] >>>> <mailto:[email protected]>。 >>>> 通过以下网址访问此论坛:http://groups.google.com >>>> /group/perlchina?hl=zh-CN。 >>>> 要查看更多选项,请访问 >>>> https://groups.google.com/groups/opt_out。 >>>> >>>> >>>> >>>> -- >>>> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina >>>> Mongers 讨论组”论坛。 >>>> 要退订此论坛并停止接收此论坛的电子邮件,请发送电 子邮件 >>>> 到 [email protected] >>>> <mailto:[email protected]>。 >>>> 要向此网上论坛发帖,请发送电子邮件至 >>>> [email protected] >>>> <mailto:[email protected]>。 >>>> 通过以下网址访问此论坛:http://groups.google.com >>>> /group/perlchina?hl=zh- CN。 >>>> <http://groups.google.com/group/perlchina?hl=zh-CN%A1%A3> >>>> 要查看更多选项,请访问 https://groups.google.com >>>> /groups/opt_out。 >>>> <https://groups.google.com/groups/opt_out%A1%A3> >>>> >>>> >>> >>> -- >>> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina >>> Mongers 讨论组”论坛。 >>> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 >>> [email protected] >>> <mailto:perlchina%[email protected]>。 >>> 要向此网上论坛发帖,请发送电子邮件至 >>> [email protected] >>> <mailto:[email protected]>。 >>> 通过以下网址访问此论坛:http://groups.google.com/group >>> /perlchina?hl=zh-CN。 >>> <http://groups.google.com/group/perlchina?hl=zh-CN%A1%A3> >>> 要查看更多选项,请访问 https://groups.google.com/groups >>> /opt_out。 <https://groups.google.com/groups/opt_out%A1%A3> >>> >>> >>> >>> -- >>> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina >>> Mongers 讨论组”论坛。 >>> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 >>> [email protected] >>> <mailto:[email protected]>。 >>> 要向此网上论坛发帖,请发送电子邮件至 >>> [email protected] <mailto:[email protected]>。 >>> 通过以下网址访问此论坛:http://groups.google.com /group >>> /perlchina?hl=zh-CN。 >>> <http://groups.google.com/group/perlchina?hl=zh-CN%A1%A3> >>> 要查看更多选项,请访问 https://groups.google.com /groups >>> /opt_out。 <https://groups.google.com/groups/opt_out%A1%A3> >>> >>> >> >> -- >> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina >> Mongers 讨论组”论坛。 >> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 >> [email protected] >> <mailto:perlchina%[email protected]>。 >> 要向此网上论坛发帖,请发送电子邮件至 >> [email protected] <mailto:[email protected]>。 >> 通过以下网址访问此论坛:http://groups.google.com/group >> /perlchina?hl=zh-CN。 >> <http://groups.google.com/group/perlchina?hl=zh-CN%A1%A3> >> 要查看更多选项,请访问 https://groups.google.com/groups >> /opt_out。 <https://groups.google.com/groups/opt_out%A1%A3> >> >> >> >> -- >> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨 >> 论组”论坛。 >> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 >> [email protected] >> <mailto:[email protected]>。 >> 要向此网上论坛发帖,请发送电子邮件至 [email protected] >> <mailto:[email protected]>。 >> 通过以下网址访问此论坛:http://groups.google.com /group >> /perlchina?hl=zh-CN。 >> <http://groups.google.com/group/perlchina?hl=zh-CN%A1%A3> >> 要查看更多选项,请访问 https://groups.google.com /groups >> /opt_out。 <https://groups.google.com/groups/opt_out%A1%A3> >> >> > > -- > 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨 > 论组”论坛。 > 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 > [email protected] > <mailto:perlchina%[email protected]>。 > 要向此网上论坛发帖,请发送电子邮件至 [email protected] > <mailto:[email protected]>。 > 通过以下网址访问此论坛:http://groups.google.com/group > /perlchina?hl=zh-CN。 > <http://groups.google.com/group/perlchina?hl=zh-CN%A1%A3> > 要查看更多选项,请访问 https://groups.google.com/groups /opt_out。 > <https://groups.google.com/groups/opt_out%A1%A3> > > > > -- > 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组” > 论坛。 > 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 > [email protected]。 > 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 > 通过以下网址访问此论坛:http://groups.google.com /group > /perlchina?hl=zh-CN。 > <http://groups.google.com/group/perlchina?hl=zh-CN%A1%A3> > 要查看更多选项,请访问 https://groups.google.com /groups/opt_out。 > <https://groups.google.com/groups/opt_out%A1%A3> > > -- 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 [email protected]。 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 通过以下网址访问此论坛:http://groups.google.com/group/perlchina?hl=zh-CN。 要查看更多选项,请访问 https://groups.google.com/groups/opt_out。
