0

I have the username: root and password: root. I cannot connect to my db whenever I type root in my password. It keeps saying ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) However, when I press enter leaving the password empty, I can go in.
In my .env file I have:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=fin_book_09
DB_USERNAME=root
DB_PASSWORD=root

I also changed my config/database to:

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', 'root'),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

I can't seem to understand why this is happening.

Ven
  • 89
  • 1
  • 8
  • Does this answer your question? [Laravel shows error access denied for user](https://stackoverflow.com/questions/54824248/laravel-shows-error-access-denied-for-user) – STA Jun 07 '20 at 06:39
  • I tried that but it still didn't work – Ven Jun 07 '20 at 06:47
  • Clear your config and try again `php artisan config:clear` – STA Jun 07 '20 at 06:48
  • I tried that too and still not working, I don't understand – Ven Jun 07 '20 at 06:52
  • Can you confirm that you can connect to the database with those credentials i.e. does running `mysql -uroot -proot` allow you access or return an error? – Rwd Jun 07 '20 at 10:34

2 Answers2

0

Check Your Database connection in PHPMyAdmin. PHPMyAdmin Default user name: 'root' Password : ''

for password set, SET PASSWORD FOR root@localhost = PASSWORD('your_root_password');

Nurullah
  • 82
  • 3
  • is it not within the project files? Since I'm going to use `create database` right after? – Ven Jun 07 '20 at 06:43
0

If you are serving your application by laravel command php artisan serve. Then close that and serve again.

And if still not work try to regenerate your application key again.

php artisan key:generate

Hope it helps :)

Maulik Shah
  • 1,040
  • 1
  • 7
  • 17