1

I have checked this issue on this forum but couldn't solve it.

.env file

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

and database.php

'mysql' => [
    'driver' => 'mysql',
    'url' => env('DATABASE_URL'),
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'channelable'),
    '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 am sure that the database username and password are: root

I use php artisan config:clear and php artisan cache:clear commands but still show me a error.

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = channelable and table_name = migrations and table_type = 'BASE TABLE')

Can you help me?

enter image description here

Shibbir
  • 1,963
  • 2
  • 25
  • 48
  • Try using `localhost` instead of IP `127.0.0.1` for hostname – Rikesh Jun 08 '22 at 08:30
  • Tired but still showing me that same error. – Shibbir Jun 08 '22 at 08:31
  • Have you check and follow mention steps in this https://stackoverflow.com/questions/17975120/access-denied-for-user-rootlocalhost-using-password-yes-no-privileges – Rikesh Jun 08 '22 at 08:32
  • do you use docker ? – Lk77 Jun 08 '22 at 08:35
  • Yes, on my project folder I can see docker – Shibbir Jun 08 '22 at 08:35
  • 1
    Does this answer your question? [Docker MYSQL '\[2002\] Connection refused'](https://stackoverflow.com/questions/40561433/docker-mysql-2002-connection-refused) – Justinas Jun 08 '22 at 08:40
  • E.g. on Mac Docker instead of `localhost` we must use `docker.for.mac.localhost` as `localhost` points to internal IP of Docker, and not to internal IP of machine (host) – Justinas Jun 08 '22 at 08:41
  • What you mean `i can see docker`? are you serving your application by running `php artisan serve` or `docker compose ...`? If you're using first one, then you're not probably using docker at all, you just got it in your project or etc. – Atlas-Pio Jun 08 '22 at 17:07

3 Answers3

0

Try this in terminal:

sudo mysql -u root

mysql> ALTER USER the_user IDENTIFIED WITH mysql_native_password BY 'the_password';
  • I got this: https://prnt.sc/-ixVb9T7PZoP – Shibbir Jun 08 '22 at 08:47
  • Create a new user with all privileges and try again – Max Boyanov Jun 08 '22 at 08:53
  • I don't understand. Something is wrong: https://prnt.sc/rVfRSlPvWk0F and got this error: ` SQLSTATE[HY000] [1045] Access denied for user 'shibbir'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = channelable and table_name = migrations and table_type = 'BASE TABLE')` – Shibbir Jun 08 '22 at 09:03
  • Have you tried executing with the host? ALTER USER root@127.0.0.1 IDENTIFIED WITH mysql_native_password BY 'root'; – Max Boyanov Jun 08 '22 at 09:16
  • If you run the command above, it defaults to users with host "%". Therefore, when creating a user, you can specify '%' as the host, thereby assigning the user to any host – Max Boyanov Jun 08 '22 at 09:24
  • I am trying the command. – Shibbir Jun 08 '22 at 09:31
  • Ah no luck, can we start chat? – Shibbir Jun 08 '22 at 09:33
  • I had an identical problem, I solved the problem with the above command. Thought it would help you. Now I don't know how to help you, I tried)) – Max Boyanov Jun 08 '22 at 09:45
0

I faced the same issue few weeks ago and even after changing the user details from terminal, the error persistsed.

Below was how I resolved it. Enclose the DB_USERNAME and DB_PASSWORD values in double quotes as shown below:

DB_USERNAME="root"
DB_PASSWORD="root"

Maybe that will help.

0

this error happens when you are providing wrong username or passowd to the .env setting for the mysqli driver to connect to mysql i dont thinks by adding DB_USERNAME="root" DB_PASSWORD="root" check your credentials or reset your password and then try again