如何告诉DBD :: mysql mysql.sock在哪里? [英] How do I tell DBD::mysql where mysql.sock is?

查看:106
本文介绍了如何告诉DBD :: mysql mysql.sock在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在DBI中使用DBD :: mysql,尝试连接数据库时出现以下错误.

Using DBD::mysql with DBI, I am getting the following error when attempting to connect to the database.

DBI connect('database=mydb:host=localhost','someuser',...) failed: Can't connect 
   to local MySQL server through socket '/tmp/mysql.sock' (2) at ./myscript.pl line 97

是的,MySQL已启动并正在运行.问题是mysql.sock不在/tmp中.
我知道mysql.sock的位置,并且我目前已经对其进行了黑客攻击,因此它可以正常工作,我创建了一个指向mysql.sock文件当前位置的软链接.我宁愿不更改MySQL配置,尽管这可能是最简单的操作.

有没有办法进入DBD :: mysql并将其配置为在正确的位置查找mysql.sock?

Yes MySQL is up and running. The problem is that mysql.sock is not in /tmp.
I know the location of mysql.sock and I currently have it hacked so that it works, I created a soft link to the current location of the mysql.sock file. I would rather not change the MySQL configuration, though this would probably be the easiest thing to do.

Is there a way to go into DBD::mysql and configure it to look for mysql.sock in the correct location?

推荐答案

您可以在connect方法中指定套接字的位置

You can specify the location of the socket in the connect method

my $dbh = DBI->connect("DBI:mysql:database=dbname;host=localhost;mysql_socket=/path/to/mysql.sock","someuser","somepassword", {'RaiseError' => 1});

有关更多信息,请参阅文档这里

For further information please have a look at the docs here

这篇关于如何告诉DBD :: mysql mysql.sock在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆