ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES) Using Debian: I have uninstalled and reinstalled mysql using apt-get remove --purge mysql*, then reinstalled. Running mysql_secure_installation does not work because it will not accept my password. I hoped clearing all things mysql related would reset the password used for this. How can I have a clean start with mysql? How can I prevent this from happening in the future?
Thank you
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!
Accepted Answer
Hello,
The error you’re encountering, “ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)”, is a common MySQL authentication issue. It seems like there’s a problem with the root password or the way MySQL is interpreting your login credentials. Here’s a step-by-step guide to resolve this and ensure a clean start with MySQL on Debian:
Please be aware that removing the MySQL directory, specifically
/var/lib/mysql
, will permanently delete all existing MySQL databases and data stored on your server.
Uninstall MySQL Completely:
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt update
Reinstall MySQL:
sudo apt install mysql-server
Secure MySQL Installation:
mysql_secure_installation
script:
sudo mysql_secure_installation
Troubleshooting the Root Password:
sudo systemctl stop mysql
sudo mysqld_safe --skip-grant-tables &
mysql -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
EXIT;
new_password
with your new root password. Then restart MySQL:
sudo systemctl restart mysql
Besides that, check for any error logs in /var/log/mysql/
for more specific error messages and ensure that there are no other conflicting services or incorrect configurations.
Best,
Bobby
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.