By riyastp04
I have gone through the tutorial and done the exact but my when I try to open in website it is showing Error!: SQLSTATE[HY000] [1045] Access denied for user ‘user’@‘localhost’ (using password: YES)
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there @riyastp04,
Are you using the correct password for your connection string in your website configuration file?
Did you get any errors when you ran the CREATE USER query:
CREATE USER 'example_user'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
Also, did you run the grant privileges query too:
GRANT ALL ON example_database.* TO 'example_user'@'%';
Regards, Bobby
Hey,
The error SQLSTATE[HY000] [1045] Access denied for user 'user'@'localhost' (using password: YES) indicates that the MySQL server is rejecting the credentials provided by your application. Here’s how to troubleshoot and resolve the issue:
Check the database credentials used in your application configuration:
.env for Laravel or config.php for many PHP applications).localhost or 127.0.0.1.3306 unless explicitly changed.Example .env configuration for Laravel:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password
Manually test the credentials from the terminal:
mysql -u your_username -p -h 127.0.0.1 your_database_name
your_username, your_password, and your_database_name with your actual values.If the credentials fail, grant the necessary privileges to the user in MySQL:
root or an admin user:sudo mysql -u root -p
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'localhost' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;
Ensure that MySQL and Apache services are running:
sudo systemctl restart mysql
sudo systemctl restart apache2
Sometimes, the MySQL user is configured to use an authentication plugin like auth_socket, which may prevent password-based login. Check the authentication method:
root:sudo mysql -u root -p
SELECT user, host, plugin FROM mysql.user WHERE user = 'your_username';
auth_socket, change it to mysql_native_password:ALTER USER 'your_username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
FLUSH PRIVILEGES;
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.