0

I am using laravel 5.3.

Recently I have setup my project on Ubuntu 14.04 and moved my project to LAMP, before this it was on WAMP.

My .env file is as:

APP_ENV=local
APP_DEBUG=true
APP_KEY=somebase64key
DB_HOST=localhost
DB_DATABASE="local.d2d.com"
DB_USERNAME=d2d
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file

Yes, I have user d2d and have all privileges on database local.d2d.com in mysql.

My config/database.php is as:

<?php

return [
    'fetch' => PDO::FETCH_CLASS,
    'default' => 'mysql',
    'connections' => [
        'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST'),
            'database'  => env('DB_DATABASE'),
            'username'  => env('DB_USERNAME'),
            'password'  => env('DB_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ]
    ],

    'migrations' => 'migrations',
    'redis' => [
        'cluster' => false,
        'default' => [
            'host'     => '127.0.0.1',
            'port'     => 6379,
            'database' => 0,
        ]
    ]
];

While running php artisan migrate, I am getting following error:

[Illuminate\Database\QueryException] SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = local.d2d.com and table_name = migrations)

[Doctrine\DBAL\Driver\PDOException] SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) [PDOException] SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

You can see I am NOT USING root user anywhere still I am facing this issue. Even in the connection error you may find the database is information_schema instead of local.d2d.com.

Yes, I have ran php artisan config:clear, php artisan cache:clear, php artisan view:clear, php artisan clear-compiled and php artisan optimize many times.

Can anyone help?

Jimi
  • 15
  • 3
  • did you restarted your laravel server? If else stop the current server, start it again and run the config and cache clear commands and let me know. – Arun Code Jan 09 '17 at 07:17
  • @ArunCode I have run ```sudo service apache2 restart``` and cleared config as well as cache, still the same problem is there. – Jimi Jan 09 '17 at 07:23
  • @R.Mazarei I had also tried it but it seems not working. – Jimi Jan 09 '17 at 07:23
  • also clear your config cache. – Frnak Jan 09 '17 at 07:28
  • I didn't notice the error message so I deleted my comment, it wasn't what I thought. – Rouhollah Mazarei Jan 09 '17 at 07:31
  • If you are using laravel-doctrine as ORM make sure you add the ServiceProvider to the providers array and publish the config by running `php artisan vendor:publish --tag="config"`. I'm not sure but I think you must have a password setup. – Mirceac21 Jan 09 '17 at 07:43
  • @Jimi check if you find a solution here http://stackoverflow.com/a/31154458/3918473 – Gayan Jan 09 '17 at 07:51

1 Answers1

0

Change your config/database.php like this:

<?php
    ...
    'mysql' => [
        ...
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'example'),
        'username'  => env('DB_USERNAME', 'root'),
        'password'  => env('DB_PASSWORD', 'root'),
        ...
    ],
    ...

then

php artisan cache:clear
php artisan config:cache
Cong Chen
  • 2,436
  • 12
  • 21