Docker Laravel [2002] Connection拒绝了

时间:2018-05-31 02:15:12

标签: php mysql laravel docker

我只是在安装docker,我正在尝试设置我的数据库。我已经能够连接到phpmyadmin但是当我运行php artisan migrate:刷新我的项目里面的Laradock我得到以下错误:

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = studious and table_name = migrations)

  at /var/www/studious/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 

  Exception trace:

  1   PDOException::("SQLSTATE[HY000] [2002] Connection refused")
      /var/www/studious/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

  2   PDO::__construct("mysql:host=mysql;port=3307;dbname=studious", "root", "root", [])
      /var/www/studious/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

这是我的.env文件:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:4ToWyL1QCZfn7Ixa+Wldc47JNAa2lleoqArOBzI6aRw=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3307
DB_DATABASE=studious
DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

需要注意的一点是,我必须将Laradock的.env上的端口更改为3307,因为它不允许我连接到3306.这就是看起来像:

### MYSQL #################################################

MYSQL_VERSION=5.6
MYSQL_DATABASE=default
MYSQL_USER=default
MYSQL_PASSWORD=secret
MYSQL_PORT=3307
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d

我不确定如何使其发挥作用或理解为什么会发生这种情况。我已经尝试更改我的项目中的config.database文件以获得相同的mysql凭据,但这没有用。

0 个答案:

没有答案