开发者社区> 问答> 正文

php使用pdo连接数据提示错误怎么解决---->Can't connect to local MySQL server through socket '/tmp/mysql.sock'

$dsn="mysql:dbname=**;host=localhost";
$db_user='*';
$db_pass='';
try{
$pdo=new PDO($dsn,$db_user,$db_pass);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}catch(PDOException $e){
echo '数据库连接失败'.$e->getMessage();
}

错误是:SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

展开
收起
奥维马 2016-07-06 12:28:18 3529 0
1 条回答
写回答
取消 提交回答
  • 旺旺:nectar2。

    您好,

    那请问您的本地服务器中有没有安装mysql服务端,/tmp/mysql.sock文件是否存在呢?

    2019-07-17 19:52:00
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像