Consider:
./mysqladmin -u root -p** '_redacted_'
Output (including typing the password):
Enter password:
mysqladmin: connect to server at 'localhost' failed error:
'Access denied for user 'root'@'localhost' (using password: YES)'
How can I fix this?
Use the ALTER USER command and change the authentication method to log into MySQL as root: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password'; This command changes the password for the user root and sets the authentication method to mysql_native_password.
To resolve the error, you must create a user with the following command: mysql> GRANT ALL ON *. * to user_name@localhost IDENTIFIED BY 'password'; Replace user_name with the user's username and password with the user's password.
Solution 1: Sudo then Change Password If you get the “access denied” error, one way to solve it is by using sudo to log in to mysql and change the root password. Step 1: Open the command line on your system. Step 3: Enter the password for this account.
All solutions I found were much more complex than necessary and none worked for me. Here is the solution that solved my problem. There isn't any need to restart mysqld or start it with special privileges.
sudo mysql -- for MySQL ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; -- for MariaDB ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('root');
With a single query we are changing the auth_plugin to mysql_native_password and setting the root password to root (feel free to change it in the query).
Now you should be able to log in with root. More information can be found in MySQL documentation or MariaDB documentation.
(Exit the MySQL console with Ctrl + D or by typing exit.)
/etc/my.cnf
or /etc/mysql/my.cnf
, depending on your distribution.skip-grant-tables
under [mysqld]
mysql -u root -p
mysql> flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
mysql -u root -p
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With