Can't connect to Mysql server with Laravel 5

M Hadizadeh

When i add a MySQL connection to my laravel installation it does not seem to work and error :

QueryException SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I hope you guys know, because i have no idea.

database.php

/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/

'default' => env('DB_CONNECTION', 'mysql'),

/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/

'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'database' => env('DB_DATABASE', database_path('database.sqlite')),
        'prefix' => '',
    ],


        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'anirun'),
        'username' => env('DB_USERNAME', 'root'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

    'pgsql' => [
        'driver' => 'pgsql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '5432'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
        'schema' => 'public',
        'sslmode' => 'prefer',
    ],

    'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '1433'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
    ],

],

/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/

'migrations' => 'migrations',

/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/

'redis' => [

    'client' => 'predis',

    'default' => [
        'host' => env('REDIS_HOST', 'localhost'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => 0,
    ],

],
Joan Nguyen

1, You replace default by 'default' => env('DB_DRIVER', 'mysql')

2, You need add key 'mysql' => [ to connections :

    'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'database' => env('DB_DATABASE', database_path('database.sqlite')),
        'prefix' => '',
    ],
    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'anirun'),
        'username' => env('DB_USERNAME', 'root'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

    'pgsql' => [
        'driver' => 'pgsql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '5432'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
        'schema' => 'public',
        'sslmode' => 'prefer',
    ],

    'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '1433'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
    ],
],

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can't connect to MySQL on live with Laravel 5

From Dev

Can't connect to Mysql server with Laravel 5.2

From Dev

Can't connect to mysql server from command prompt [Laravel]

From Dev

Can't connect to MySQL server on 'domain' (111)

From Dev

Can't startup and connect to MySQL server

From Dev

Can't connect to MySQL server on 'localhost' (111)

From Dev

Can't connect to Remote MySQL Server (10061)

From Dev

Can't connect to MySQL server on 'domain' (111)

From Dev

MySQL Can't Connect to External Server

From Dev

JDBC - can't connect remotely to MySQL Server

From Dev

Can't connect to local MySQL server

From Dev

SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (61) error Laravel 4.1

From Dev

Can't connect to MySQL server on 'localhost' (10061), but can via PHP

From Dev

Laravel 5 application can't connect MariaDB engine in docker container

From Dev

Laravel 5 application can't connect MariaDB engine in docker container

From Dev

Can't Connect to DelphiXE5 AND SQL SERVER 2012

From Dev

Can't connect to Vagrant using HeidiSQL: "Can't connect to MySQL server on 'localhost'"

From Dev

2003, "Can't connect to MySQL server on '192.168.1.xxx' (10060)

From Dev

Symfony2 can't connect to MySQL server on '192.168.1.50' (113)

From Dev

"Can't connect to local MySQL server" in docker-compose

From Dev

Can't connect to MySQL server on (ip or domain name)

From Dev

#2003 - Can't connect to MySQL server on 'localhost' (10061)

From Dev

Can't connect to MySQL server on '127.0.0.1' (10061) (2003)

From Dev

SQLSTATE[HY000] [2003] Can't connect to MySQL server

From Dev

Can't connect to remote MySQL server on AWS, but ssh tunnel works

From Dev

Python MySQL Connector: Can't connect to server with SSL

From Dev

Can't connect to remote server using MySQL Workbench on mac

From Dev

Can't connect to MySQL server on (ip or domain name)

From Dev

Why it can't connect to local mysql server due ERROR 2002?

Related Related

  1. 1

    Can't connect to MySQL on live with Laravel 5

  2. 2

    Can't connect to Mysql server with Laravel 5.2

  3. 3

    Can't connect to mysql server from command prompt [Laravel]

  4. 4

    Can't connect to MySQL server on 'domain' (111)

  5. 5

    Can't startup and connect to MySQL server

  6. 6

    Can't connect to MySQL server on 'localhost' (111)

  7. 7

    Can't connect to Remote MySQL Server (10061)

  8. 8

    Can't connect to MySQL server on 'domain' (111)

  9. 9

    MySQL Can't Connect to External Server

  10. 10

    JDBC - can't connect remotely to MySQL Server

  11. 11

    Can't connect to local MySQL server

  12. 12

    SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (61) error Laravel 4.1

  13. 13

    Can't connect to MySQL server on 'localhost' (10061), but can via PHP

  14. 14

    Laravel 5 application can't connect MariaDB engine in docker container

  15. 15

    Laravel 5 application can't connect MariaDB engine in docker container

  16. 16

    Can't Connect to DelphiXE5 AND SQL SERVER 2012

  17. 17

    Can't connect to Vagrant using HeidiSQL: "Can't connect to MySQL server on 'localhost'"

  18. 18

    2003, "Can't connect to MySQL server on '192.168.1.xxx' (10060)

  19. 19

    Symfony2 can't connect to MySQL server on '192.168.1.50' (113)

  20. 20

    "Can't connect to local MySQL server" in docker-compose

  21. 21

    Can't connect to MySQL server on (ip or domain name)

  22. 22

    #2003 - Can't connect to MySQL server on 'localhost' (10061)

  23. 23

    Can't connect to MySQL server on '127.0.0.1' (10061) (2003)

  24. 24

    SQLSTATE[HY000] [2003] Can't connect to MySQL server

  25. 25

    Can't connect to remote MySQL server on AWS, but ssh tunnel works

  26. 26

    Python MySQL Connector: Can't connect to server with SSL

  27. 27

    Can't connect to remote server using MySQL Workbench on mac

  28. 28

    Can't connect to MySQL server on (ip or domain name)

  29. 29

    Why it can't connect to local mysql server due ERROR 2002?

HotTag

Archive