<small id='oM08z'></small><noframes id='oM08z'>

  • <legend id='oM08z'><style id='oM08z'><dir id='oM08z'><q id='oM08z'></q></dir></style></legend>
      • <bdo id='oM08z'></bdo><ul id='oM08z'></ul>
      <i id='oM08z'><tr id='oM08z'><dt id='oM08z'><q id='oM08z'><span id='oM08z'><b id='oM08z'><form id='oM08z'><ins id='oM08z'></ins><ul id='oM08z'></ul><sub id='oM08z'></sub></form><legend id='oM08z'></legend><bdo id='oM08z'><pre id='oM08z'><center id='oM08z'></center></pre></bdo></b><th id='oM08z'></th></span></q></dt></tr></i><div id='oM08z'><tfoot id='oM08z'></tfoot><dl id='oM08z'><fieldset id='oM08z'></fieldset></dl></div>

      <tfoot id='oM08z'></tfoot>

        使用 Docker 我收到错误:“SQLSTATE[HY000] [2002] 没有这样的文件或目录"

        Using Docker I get the error: quot;SQLSTATE[HY000] [2002] No such file or directoryquot;(使用 Docker 我收到错误:“SQLSTATE[HY000] [2002] 没有这样的文件或目录)
            <tbody id='D2Udj'></tbody>

            <legend id='D2Udj'><style id='D2Udj'><dir id='D2Udj'><q id='D2Udj'></q></dir></style></legend>

            <i id='D2Udj'><tr id='D2Udj'><dt id='D2Udj'><q id='D2Udj'><span id='D2Udj'><b id='D2Udj'><form id='D2Udj'><ins id='D2Udj'></ins><ul id='D2Udj'></ul><sub id='D2Udj'></sub></form><legend id='D2Udj'></legend><bdo id='D2Udj'><pre id='D2Udj'><center id='D2Udj'></center></pre></bdo></b><th id='D2Udj'></th></span></q></dt></tr></i><div id='D2Udj'><tfoot id='D2Udj'></tfoot><dl id='D2Udj'><fieldset id='D2Udj'></fieldset></dl></div>
                  <bdo id='D2Udj'></bdo><ul id='D2Udj'></ul>

                  <small id='D2Udj'></small><noframes id='D2Udj'>

                • <tfoot id='D2Udj'></tfoot>

                  本文介绍了使用 Docker 我收到错误:“SQLSTATE[HY000] [2002] 没有这样的文件或目录"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Docker 创建一个容器,以在我的 Mac 上测试基于 PHP 和 MySQL 构建的 Web 应用程序.我的 PHP 应用程序是使用用于 MVC 和路由的 Fat-Free 框架构建的.我有两个 Dockerfile,一个用于 MySQL,一个用于 PHP.我已经成功使用测试 Docker 应用程序,所以我相信我的图像安装正确.

                  I'm using Docker to create a container to test my web app built on PHP and MySQL on my Mac. My PHP app is built using Fat-Free Framework for MVC and routing. I have two Dockerfiles, one for MySQL and one for PHP. I've used test Docker applications successfully, so I believe my images are installed correctly.

                  错误的主要部分:

                  Internal Server Error
                  
                  SQLSTATE[HY000] [2002] No such file or directory
                  
                  [fatfree/lib/DB/SQL.php:466] PDO->__construct('mysql:host=127.0.0.1;port=3306;dbname=robohome','root','password',array(1002=>'SET NAMES utf8;'))
                  [fatfree/app/Controllers/Controller.php:24] DBSQL->__construct('mysql:host=127.0.0.1;port=3306;dbname=robohome','root','password')
                  

                  注意,如果我使用 127.0.0.1 而不是 localhost 进行连接,我会收到一个稍微不同的错误:SQLSTATE[HY000] [2002] Connection denied

                  Note, if I connect using 127.0.0.1 instead of localhost I get a slightly different error that says: SQLSTATE[HY000] [2002] Connection refused

                  我的 PHP Dockerfile:

                  My PHP Dockerfile:

                  FROM php:5.6-apache
                  
                  RUN docker-php-ext-install mysqli pdo pdo_mysql
                  RUN a2enmod rewrite
                  

                  我的 MySQL Dockerfile:

                  My MySQL Dockerfile:

                  FROM mysql:5.7
                  
                  ENV MYSQL_ROOT_PASSWORD password
                  ENV MYSQL_DATABASE robohome
                  
                  COPY ./schema.sql /docker-entrypoint-initdb.d/
                  

                  我的 Controller.php 文件,其中错误提到第 24 行:

                  My Controller.php file where the error mentions line 24:

                  <?php
                  
                  namespace Controllers;
                  
                  class Controller
                  {
                      protected $f3;
                      protected $db;
                  
                      public function __construct()
                      {
                          $f3 = Base::instance();
                          $this->f3 = $f3;
                  
                          $mysqlServerName = $f3->get("MYSQL_SERVERNAME");
                          $mysqlDatabseName = $f3->get("MYSQL_DBNAME");
                  
                          //$container = DIContainerBuilder::buildDevContainer(); <-Not used currently
                  
                          //Below is line 24 referred to in the error
                          $db = new DBSQL(
                              "mysql:host={$mysqlServerName};port=3306;dbname={$mysqlDatabseName}",
                              $f3->get("MYSQL_USERNAME"),
                              $f3->get("MYSQL_PASSWORD")
                          );
                  
                          $this->db = $db;
                      }
                  

                  那些 MYSQL_* 值是从 .ini 文件中提取的:

                  Those MYSQL_* values are pulled from an .ini file:

                  MYSQL_SERVERNAME = "localhost" <-This is what I've tried changing to 127.0.0.1
                  MYSQL_USERNAME = "root"
                  MYSQL_PASSWORD = "password"
                  MYSQL_DBNAME = "robohome"
                  

                  我的 Docker 撰写文件:

                  My Docker compose file:

                  version: '2'
                  
                  services:
                    web:
                      build: ./docker/php
                      ports:
                        - 80:80
                      volumes:
                        - .:/var/www/html/
                      links:
                        - db
                    db:
                      build: ./docker/mysql
                      ports:
                        - 3306
                  

                  我通过执行 docker-compose up --build -d 来运行它.然后我可以从 docker ps 得到的输出是:

                  I run this by doing docker-compose up --build -d. The output I can then get from docker ps is:

                  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
                  f35066a16586        robohomeweb_mysql   "docker-entrypoint.sh"   3 minutes ago       Up 2 seconds        0.0.0.0:32777->3306/tcp   robohomeweb_mysql_1
                  86d34eb34583        robohomeweb_php     "apache2-foreground"     3 minutes ago       Up 2 seconds        0.0.0.0:80->80/tcp        robohomeweb_php_1
                  

                  如果我改为在前台运行,我会得到以下输出:

                  If I run in the foreground instead, I get the following output:

                  Building php
                  Step 1 : FROM php:5.6-apache
                   ---> 8f9b7e57129a
                  Step 2 : RUN docker-php-ext-install mysqli pdo pdo_mysql
                   ---> Using cache
                   ---> fadd8f9e7207
                  Step 3 : RUN a2enmod rewrite
                   ---> Using cache
                   ---> 9dfed7fdc60f
                  Successfully built 9dfed7fdc60f
                  Building mysql
                  Step 1 : FROM mysql:5.7
                   ---> eda6a4884645
                  Step 2 : ENV MYSQL_ROOT_PASSWORD password
                   ---> Using cache
                   ---> 759895ac5772
                  Step 3 : ENV MYSQL_DATABASE robohome
                   ---> Using cache
                   ---> e926c5ecc088
                  Step 4 : COPY ./schema.sql /docker-entrypoint-initdb.d/
                   ---> Using cache
                   ---> cf5d00aa8020
                  Successfully built cf5d00aa8020
                  Starting robohomeweb_php_1
                  Starting robohomeweb_mysql_1
                  Attaching to robohomeweb_mysql_1, robohomeweb_php_1
                  php_1    | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
                  php_1    | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
                  php_1    | [Sun Oct 16 20:21:17.944575 2016] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.26 configured -- resuming normal operations
                  php_1    | [Sun Oct 16 20:21:17.946919 2016] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
                  mysql_1  | 2016-10-16T20:21:18.036272Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
                  mysql_1  | 2016-10-16T20:21:18.038330Z 0 [Note] mysqld (mysqld 5.7.16) starting as process 1 ...
                  mysql_1  | 2016-10-16T20:21:18.043331Z 0 [Note] InnoDB: PUNCH HOLE support available
                  mysql_1  | 2016-10-16T20:21:18.043603Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
                  mysql_1  | 2016-10-16T20:21:18.043951Z 0 [Note] InnoDB: Uses event mutexes
                  mysql_1  | 2016-10-16T20:21:18.044077Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
                  mysql_1  | 2016-10-16T20:21:18.044260Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
                  mysql_1  | 2016-10-16T20:21:18.044414Z 0 [Note] InnoDB: Using Linux native AIO
                  mysql_1  | 2016-10-16T20:21:18.045150Z 0 [Note] InnoDB: Number of pools: 1
                  mysql_1  | 2016-10-16T20:21:18.045620Z 0 [Note] InnoDB: Using CPU crc32 instructions
                  mysql_1  | 2016-10-16T20:21:18.047629Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
                  mysql_1  | 2016-10-16T20:21:18.057705Z 0 [Note] InnoDB: Completed initialization of buffer pool
                  mysql_1  | 2016-10-16T20:21:18.059988Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
                  mysql_1  | 2016-10-16T20:21:18.074670Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
                  mysql_1  | 2016-10-16T20:21:18.101209Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
                  mysql_1  | 2016-10-16T20:21:18.101433Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
                  mysql_1  | 2016-10-16T20:21:18.354806Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
                  mysql_1  | 2016-10-16T20:21:18.356928Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
                  mysql_1  | 2016-10-16T20:21:18.357158Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
                  mysql_1  | 2016-10-16T20:21:18.358049Z 0 [Note] InnoDB: Waiting for purge to start
                  mysql_1  | 2016-10-16T20:21:18.412987Z 0 [Note] InnoDB: 5.7.16 started; log sequence number 12179647
                  mysql_1  | 2016-10-16T20:21:18.414470Z 0 [Note] Plugin 'FEDERATED' is disabled.
                  mysql_1  | 2016-10-16T20:21:18.421833Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
                  mysql_1  | 2016-10-16T20:21:18.424144Z 0 [Note] InnoDB: Buffer pool(s) load completed at 161016 20:21:18
                  mysql_1  | 2016-10-16T20:21:18.425607Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
                  mysql_1  | 2016-10-16T20:21:18.427018Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
                  mysql_1  | 2016-10-16T20:21:18.427581Z 0 [Note] IPv6 is available.
                  mysql_1  | 2016-10-16T20:21:18.427749Z 0 [Note]   - '::' resolves to '::';
                  mysql_1  | 2016-10-16T20:21:18.428019Z 0 [Note] Server socket created on IP: '::'.
                  mysql_1  | 2016-10-16T20:21:18.456023Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
                  mysql_1  | 2016-10-16T20:21:18.456354Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
                  mysql_1  | 2016-10-16T20:21:18.480237Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
                  mysql_1  | 2016-10-16T20:21:18.488758Z 0 [Note] Event Scheduler: Loaded 0 events
                  mysql_1  | 2016-10-16T20:21:18.490880Z 0 [Note] mysqld: ready for connections.
                  mysql_1  | Version: '5.7.16'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
                  

                  根据我的研究,我尝试使用 localhost127.0.0.1 进行连接,因为它们在技术上的处理方式不同.它也可能与尝试通过套接字而不是 TCP 交谈有关.理想情况下,我想要一个解决方案,我可以将其烘焙到我的 Dockerfiles 中,这样我就不必担心记住命令或我是如何做某事的.

                  From my research, I've tried connecting using both localhost and 127.0.0.1 since they're technically treated differently. It could also be something related to trying to talk via sockets instead of TCP. Ideally I would like a solution that I can bake into my Dockerfiles so I don't have to worry about remembering commands or how I did something.

                  推荐答案

                  正如评论中有人指出的那样,您提供的 docker-compose 文件与您的问题非常相关.

                  As someone pointed out in the comments, the docker-compose file you provided is very relevant to your question.

                  docker 中 links 的文档-撰写文件说

                  The documentation for links in docker-compose files says

                  链接服务的容器可以通过与别名相同的主机名访问,如果没有指定别名,则使用服务名.

                  Containers for the linked service will be reachable at a hostname identical to the alias, or the service name if no alias was specified.

                  在您的情况下,数据库容器名为 db,因此从 PHP 容器解析 db 主机应该指向 MySQL 容器.在配置文件中将 localhost 替换为 db 应该允许 PHP 容器连接到 MySQL.

                  In your case, the database container is named db, so resolving db host from the PHP container should point you at the MySQL container. Replacing localhost with db in your config file should allow the PHP container to connect to MySQL.

                  这篇关于使用 Docker 我收到错误:“SQLSTATE[HY000] [2002] 没有这样的文件或目录"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How do I parse XML containing custom namespaces using SimpleXML?(如何使用 SimpleXML 解析包含自定义命名空间的 XML?)
                  SimpleXML SOAP response Namespace issues(SimpleXML SOAP 响应命名空间问题)
                  Problems with PHP namespaces and built-in classes, how to fix?(PHP 命名空间和内置类的问题,如何解决?)
                  Use php namespace inside function(在函数内部使用 php 命名空间)
                  unexpected #39;use#39; (T_USE) when trying to use composer(尝试使用作曲家时意外的“使用(T_USE))
                  PHP adding custom namespace using autoloader from composer(PHP使用来自作曲家的自动加载器添加自定义命名空间)

                  1. <legend id='g9Be7'><style id='g9Be7'><dir id='g9Be7'><q id='g9Be7'></q></dir></style></legend>
                      <i id='g9Be7'><tr id='g9Be7'><dt id='g9Be7'><q id='g9Be7'><span id='g9Be7'><b id='g9Be7'><form id='g9Be7'><ins id='g9Be7'></ins><ul id='g9Be7'></ul><sub id='g9Be7'></sub></form><legend id='g9Be7'></legend><bdo id='g9Be7'><pre id='g9Be7'><center id='g9Be7'></center></pre></bdo></b><th id='g9Be7'></th></span></q></dt></tr></i><div id='g9Be7'><tfoot id='g9Be7'></tfoot><dl id='g9Be7'><fieldset id='g9Be7'></fieldset></dl></div>

                          <tbody id='g9Be7'></tbody>
                      • <small id='g9Be7'></small><noframes id='g9Be7'>

                        • <bdo id='g9Be7'></bdo><ul id='g9Be7'></ul>

                          <tfoot id='g9Be7'></tfoot>