执行下面的代码报错:

$pdo = new PDO('mysql:dbname=db_test;host=localhost', 'root', '123456');
PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in test.php:2
Stack trace:
#0 test.php(2): PDO->__construct('mysql:dbname=db...', 'root', '123456')
#1 {main}
thrown in test.php on line 2

将上面 "host=localhost" 修改成 "host=127.0.0.1" 即可

$pdo = new PDO('mysql:dbname=db_test;host=127.0.0.1', 'root', '123456');

Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory的更多相关文章

  1. [PDOException] SQLSTATE[HY000] [2002] No such file or directory

    编译安装PHP7之后,在安装mysql之后,用pdo操作数据库的时候,出现了此错误[PDOException] SQLSTATE[HY000] [2002] No such file or direc ...

  2. laravel 报错SQLSTATE[HY000] [2002] No such file or directory

    在mac中执行php artisan migrate时报错 SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from i ...

  3. Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory解决方法

    今天用pdo连接mysql遇到一个奇怪的问题,host设为127.0.0.1可以连接成功,设为localhost就会报如下的错误: PHP Fatal error:  Uncaught excepti ...

  4. TP连接数据库报错:SQLSTATE[HY000] [2002] No such file or directory

     连接数据库报错:“SQLSTATE[HY000] [2002] No such file or directory”. 出现这个问题的原因是PDO无法找到mysql.sock或者mysqld.soc ...

  5. Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory'

    1.根本原因在http://askubuntu.com/questions/606732/php-fatal-error-uncaught-exception-pdoexception-with-me ...

  6. YII 错误 SQLSTATE[HY000] [2002] No such file or directory

    在使用yii的yii\db\Connnection时发生错误 <?php namespace app\controllers; use yii\web\Controller; use yii\d ...

  7. PHP连接MySQL的时候报错SQLSTATE[HY000] [2002] No such file or directory

    错误环境:Mac OS 10.10 找到mysql.sock文件的位置 $sudo find / -name mysql.sock ------结果如下---------- find: /dev/fd ...

  8. 【不积跬步,无以致千里】安装roundcube 时出现 “DSN (write): NOT OK(SQLSTATE[HY000] [2002] No such file or directory)”

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  9. SQLSTATE[HY000] [2002] No such file or directory in

    这个错误将数据库配置信息的localhost改成127.0.0.1就行了

随机推荐

  1. IDA Pro - 如何得到比较清楚的逆向伪代码

    原文地址:Question about disassembler 简介 这篇文章介绍了如何在不使用插件的IDA Hex-Rays如何得到比较清晰的伪代码.IDA Hex-Rays功能很强大,只要你提供 ...

  2. Sass-注释

    注释对于一名程序员来说,是极其重要,良好的注释能帮助自己或者别人阅读源码.在 Sass 中注释有两种方式,我暂且将其命名为: 1.类似 CSS 的注释方式,使用 ”/* ”开头,结属使用 ”*/ ”2 ...

  3. ivew 绑定时间控件

    <FormItem label="开始时间" style="width: 100%" prop="startDate"> < ...

  4. CF840E In a Trap

    题意:给你一棵节点带权树.q个询问,每次询问u到v的路径上max(a[i]^dis(i,v))? 保证u是v的祖先,i是u->v路径上的点.n,ai<=5e4. 标程: #include& ...

  5. 【leetcode】623. Add One Row to Tree

    题目如下: Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with ...

  6. python3用pygame实现播放音乐文件

    import pygameimport time #导入音乐文件file = r'C:\1.wav'pygame.mixer.init()track = pygame.mixer.music.load ...

  7. favicon.ico设置

    <link rel="shortcut icon" href="media/image/favicon.ico" />

  8. JDK1.7 hashMap源码分析

    了解HashMap原理之前先了解一下几种数据结构: 1.数组:采用一段连续的内存空间来存储数据.对于指定下标的查找,时间复杂度为O(1),对于给定元素的查找,需要遍历整个数据,时间复杂度为O(n).但 ...

  9. mybatis用distinct进行查询的问题

    一:mybatis进行distinct进行查询的时候,数据库中可能有值为null的. 如果直接这样写,这个null的都给计算出来了. select DISTINCT b.b_city from bui ...

  10. mysql8.0.15出错

    昨天装了一个wireshark,一个fiddler,导致晚上项目启动一直报init database出错,卸载了两个软件,还是不行,后来一看mysql服务停止了,但启动总是失败.按照网上的方法好了. ...