PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 18, 2022

[FIXED] SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost'

 March 18, 2022     laravel-5, mysql, php, xampp     No comments   

Issue

I make php artisan make:auth and tried to register as a new user then I get the error. I am using Xampp for MySQL and make a database name 'pari' and set user: root and password: root. After starting xampp apache and SQL server and PHP artisan serve on cmd I get the same error every time.

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select count(*) as aggregate from users where email = avinashjk1620@gmail.com)

Step 1: I have changed .env file

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

and restart using php artisan serve , but again it gave that error.

Step 2: I have changed config\database.php to-

 'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'pari'),
        'username' => env('DB_USERNAME', 'root'),
        'password' => env('DB_PASSWORD', 'root'),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

but it again gave that same error. Step 3: I tried

  php artisan cache:clear 
  php artisan config:clear

but again get same error.

Step 4: After removing password from phpmyadmin and .env and database.php I get new error-

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pari.users' doesn't exist (SQL: select count(*) as aggregate from `users` where `email` = avinashjk1620@gmail.com)

How can i fixed this error Please help me.


Solution

Make sure your database was created using utf8mb4_unicode_ci collation. This should fix your 1071 error.

Alternatively you can add Schema::defaultStringLength(191); to your boot() method in app\Providers\AppServiceProvider.php.

Edit: Make sure to add use Illuminate\Support\Facades\Schema;.



Answered By - brombeer
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing