Migrate Laravel 4: Set ErrorException

php artisan migrate:install

{"error":{"type":"ErrorException","message":"PDO::__construct(): [2002] Connection refused (trying to connect via tcp:\/\/127.0.0.1:3306)","file":"\/Applications\/MAMP\/htdocs\/DRCSports\/vendor\/laravel\/framework\/src\/Illuminate\/Database\/Connectors\/Connector.php","line":47}}

In my database.php, I updated the info to mysql

'mysql' => array(
        'driver'    => 'mysql',
        'host'      => '127.0.0.1',
        'database'  => 'Laravel_DRCSports',
        'username'  => 'root',
        'password'  => 'root',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),

I am not sure if I understand the error correctly, but for me it looks like my laravel is not connecting to mysql to the right. If so, I don’t know how to fix it.

+1
source share
7 answers

The problem was that mysql runs on port 8888 and the default port value for Laravel is 3306 (since this is the default port for mysql servers).

The solution is to add the key "port" to the array (for example: "port" => 8888), and this will do the job.

+8
source

This is what I did ... in /app/config/app.php

'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost:8889',
            'database'  => 'pic',
            'username'  => 'root',
            'password'  => 'root',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',

        ),

php-

'redis' = > (

    'cluster' => false,

    'default' => array(
        'host'     => '127.0.0.1',
        'port'     => 8888,
        'database' => 0,
    ),

),

...

+2

(Laravel 4), MySQL , 3306.

// :

'mysql' => array(
        ...
    'host' => 'localhost',
    'port' => '8889',
        ...
)

:

'mysql' => array(
        ...
    'host' => 'localhost:8889',
        ...
)

:
https://github.com/laravel/laravel/issues/1182

Laravel, DRY (Do not Repeat Yourself), :

app/config/database.php:

$my_hostname = 'localhost';
$my_port     = '8889';
$my_database = 'database';
$my_username = 'username';
$my_password = 'password';

if (App::runningInConsole()) {        // artisan runs from the command line
    // change 'localhost' to 'localhost:8889'
    $my_hostname = $my_hostname.':'.$my_port;
}

:

'mysql' => array(
    'driver'    => 'mysql',
    'host'      => $my_hostname,
    'port'      => $my_port,
    'database'  => $my_database,
    'username'  => $my_username,
    'password'  => $my_password,
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),

0

config/database.php .env.

0

:

database.php: : localhost: 8889 : 8889 , database.php, .env . 'forge', MAMP .env , MAMP MAMP (MySQL one)

0

".env".

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=8889
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=root

.

0

, , app/config/database:

'mysql' => array(
    ...

    'pconnect' => 'TRUE',
    ...
)
-1

Source: https://habr.com/ru/post/1533819/


All Articles