Laravel Access denied for user 'root'@'localhost' (using password: YES) in laravel 4.2

丶灬走出姿态 提交于 2019-12-01 17:45:32

Laravel 4.x doesn't even support ENV files. You just have to see whether settings in ./config/[env name]/database.php are correct.

The error says it all, Laravel can't connect to a DB. Check priveledges and make sure DB exists. Also, try to connect to a DB with client, like MySQL Workbench using same login and password. This will give a hint about what you can do to fix this. If you can't do this, it's not Laravel issue.

Try This

.env file

APP_ENV=local

DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=billing
DB_USERNAME=root
DB_PASSWORD=1234

config/database.php

default' => env('DB_CONNECTION', 'mysql'),


'mysql' => array(
            'driver'    => 'mysql',
            'host'      => env('DB_HOST','localhost'),
            'database'  => env('DB_DATABASE','billing'),
            'username'  => env('DB_USERNAME','root'),
            'password'  => env('DB_PASSWORD', '1234'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        )

Else checkout the .env file and check the connection

I just ran into the same problem on a new Laravel install. The problem was that I was connecting to my ubuntu localhost mysql server instead of to the vagrant box's mysql server that was on it's own ip address '192.168.10.10'. I changed over to that and all worked a charm :)

DB_HOST=localhost worked for me on Laravel 5.7

I'm test in Laravel 5.6.33 and i see this error: "Access denied for user 'root'@'localhost'", but the username and password is correct. In this version i think of this is a BUG, i change DB_HOST, from 127.0.0.1 to localhost and works!

DB_HOST=127.0.0.1 (before)
DB_HOST=localhost (after)

I faced the same problem when learning laravel using homestead, the problem happened when I try to open a page. It tried to connect to database but got rejected, although I can connect to the database using mysql command line. The problem was I had wrong assumption that since homestead forward web server request from guest to host, the same thing is also same with myqsl, but apparently it is not. Homestead has it's own mysql service, so my problem was fixed by: - homestead ssh into the guest machine - mysql -u root -p to connect to mysql command line, default password is "secret" - create the database, but you need to change your password first, just change into the same password as in mysql root's password in your host machine for convenience - exit the mysql cli and - php artisan migrate to create the tables - refresh your browser, now it should be able to connect to your db

Access denied for user 'root'@'localhost' (using password: YES)

The error was coming? The possible reason is your database connection.If the database is not connect then throw the error.

So Check the database releted all things and If all things is correct.

If not solved then change

DB_HOST=127.0.0.1 TO DB_HOST=localhost
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!