why .env file configuration in laravel is not working

旧城冷巷雨未停 提交于 2020-01-15 08:26:50

问题


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

this is my configuration for laravel 5.4 but php artisan migrate is not working and have error and the migrate error

Users-MacBook-Pro: ATP Developers php artisan migrate

In Connection.php line 664: 
SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table schema = atp_db and table_name = migrations)

In Connector.php line 87:
SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)

回答1:


Change env host entry to DB_HOST=localhost. Or add the @'127.0.0.1' credentials to mysql.




回答2:


you should write these:

DB_DATABASE = your database name
DB_USERNAME = root     
DB_PASSWORD = your password

and again run php artisan serve to make sure about saving .env and again run php artisan migrate




回答3:


The error indicates that you do not have the correct user and host combination in your database. The env file shows host is 127.0.0.1 but localhost is specified in the error. Add user@localhost entry to the database or user@% for wildcard.




回答4:


This error would indicate that you don't have a database user configured in your .env file: ''@'localhost' . Your .env should have all those fields populated with the database name and credentials you configured before running any function that connects to the database.

Here are the preliminary steps to setup your database and .env file prior to running a php artisan migrate:

Hope it helps.

Step 1: Login to your mysql and create the database.

mysql -u root -p
create database just_brew_it;

Step 2: Although you can use root to authenticate via laravel, I'd create a new user to mitigate risk of any security issues:

GRANT ALL PRIVILEGES ON just_brew_it.* TO 'brew_user'@'%' identified by 'pint0fStell@' WITH GRANT OPTION;
FLUSH privileges;

Step 3: Modify your .env with the appropriate database, username and password

DB_CONNECTION=mysql      
DB_HOST=127.0.0.1     
DB_PORT=3306     
DB_DATABASE= just_brew_it
DB_USERNAME= brew_user
DB_PASSWORD= pint0fStell@



回答5:


Indeed I had the same problem, I can not explain why Laravel indicates the old Host but the solution is to change the password.

Use below => php artisan config:cache



来源:https://stackoverflow.com/questions/48366496/why-env-file-configuration-in-laravel-is-not-working

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