I am working on a Laravel project and trying to configure my database connection. I have set the correct MySQL credentials in my .env
file, but Laravel is still trying to connect using the root
user instead of the one I specified.
My Setup
- Laravel version: Laravel Framework 11.41.3
- Database: MySQL
- OS: Ubuntu 22.04
My .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=react_breeze
DB_USERNAME=other_username_than_root
DB_PASSWORD=password
Issue:
When I run php artisan migrate
or php artisan cache:clear
, I get the following error:
SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (Connection: mysql, SQL: delete from
cache
)
When I try I get same problem
rm -rf bootstrap/cache/config.php
php artisan config:clear
php artisan cache:clear
php artisan config:cache
I am working on a Laravel project and trying to configure my database connection. I have set the correct MySQL credentials in my .env
file, but Laravel is still trying to connect using the root
user instead of the one I specified.
My Setup
- Laravel version: Laravel Framework 11.41.3
- Database: MySQL
- OS: Ubuntu 22.04
My .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=react_breeze
DB_USERNAME=other_username_than_root
DB_PASSWORD=password
Issue:
When I run php artisan migrate
or php artisan cache:clear
, I get the following error:
SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (Connection: mysql, SQL: delete from
cache
)
When I try I get same problem
rm -rf bootstrap/cache/config.php
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Share
Improve this question
edited 9 hours ago
Mark Rotteveel
109k226 gold badges155 silver badges219 bronze badges
asked yesterday
Mensour FekharMensour Fekhar
1
New contributor
Mensour Fekhar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
|
1 Answer
Reset to default 0- Laravel is still using the old cached configuration If you recently updated your .env file, Laravel may still be using cached settings.
Solution: Run the following commands to clear and refresh the configuration:
php artisan config:clear
php artisan cache:clear
php artisan config:cache
- MySQL User Permission Issue Your MySQL user (other_username_than_root) might not have sufficient privileges on the react_breeze database.
Solution: Log in to MySQL using root (if you have access) and grant the necessary privileges:
sudo mysql -u root -p
Then, execute:
GRANT ALL PRIVILEGES ON react_breeze.* TO
'other_username_than_root'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;
Try restarting MySQL:
sudo systemctl restart mysql
sail build --no-cache
. More information can be found here. – Marc H. Commented 17 hours ago