Anees
Anees

Reputation: 1

I'm beginner on laravel. And i have encountered Connection error with mysql on laravel version 5.4.16

This is my route code to add tables into firstapp db

Route::get('/', function () 
{
    Schema::create('users', function($table)
    {
        $table->increments('id');
    });        
    return view('welcome');
});

And this is config\database.php file's code

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', 'localhost'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'firstapp'),
    '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,
],

But there are two errors.Please give me solution for this.

QueryException in Connection.php line 647: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. (SQL: create table users (id int unsigned not null auto_increment primary key) default character set utf8mb4 collate utf8mb4_unicode_ci)

And

PDOException in Connector.php line 68: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

Upvotes: 0

Views: 244

Answers (3)

abhayendra
abhayendra

Reputation: 187

    'mysql' => [
        'driver' => 'mysql',
        'host' => 'localhost',
        'port' => '3306',
        'database' =>'firstapp',
        'username' => 'root',
        'password' => '',
        'unix_socket' => '',
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
],

Please Try it

Upvotes: 0

Hardika Satasiya
Hardika Satasiya

Reputation: 354

You have to modify env file. There is database configurations that has to modified first than you have to modify database.php file like

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=Your Db Name
DB_USERNAME=Your Db username
DB_PASSWORD=Your Db Password

Upvotes: 4

Vahe Galstyan
Vahe Galstyan

Reputation: 1731

You should add .env file, see .envexample, and add db configurations, hostname, password, db name.

Upvotes: 0

Related Questions