mysql password for new LAM

OS: ubuntu 16.04 message: Error: Access denied for user ‘root’@‘localhost’ (using password: YES)

Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
August 3, 2023


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';

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';
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.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel