OS: ubuntu 16.04 message: Error: Access denied for user ‘root’@‘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!
Heya,
If MySQL was configured properly, you should be able to get the password from the /root/.my.cnf file.
Alternatively, if that file is not there, and If you have forgotten your MySQL root password, you will need to reset it. The process for resetting the MySQL root password varies depending on your operating system and the version of MySQL you are using. Below are general steps to reset the MySQL root password:
Stop MySQL Server: First, stop the MySQL server. The process to stop MySQL depends on your operating system.
sudo service mysql stop
Start MySQL in Safe Mode: Start the MySQL server in safe mode with the --skip-grant-tables option. This will allow you to log in to the MySQL server without a password as the root user
sudo mysqld_safe --skip-grant-tables &
Connect to MySQL: Open a new terminal or command prompt and connect to the MySQL server as the root user without a password:
mysql -u root
Change the Root Password: Now that you are connected to the MySQL server, you can change the root password using SQL queries. Replace 'new_password' with the desired new password:
USE mysql;
UPDATE user SET authentication_string = PASSWORD('new_password') WHERE User = 'root';
FLUSH PRIVILEGES;
Note: In MySQL 5.7 and later versions, the PASSWORD function was deprecated in favor of using mysql_native_password. You can use mysql_native_password like this:
USE mysql;
UPDATE user SET authentication_string = PASSWORD('new_password') WHERE User = 'root';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
FLUSH PRIVILEGES;
exit;
sudo service mysql stop
sudo service mysql start
Once you’ve completed these steps, your MySQL root password should be changed to the new password you specified. Make sure to use the new password when connecting to the MySQL server as the root user in the future.
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.