Solve: MySQL root Access Denied Using Password Yes/No
The Post Presents a Quick Troubleshooting for MySQL Unable to Login as the Root User on Linux/Unix.
Included Link with the Recommended MySQL Database Secure Installation.
-
Check if MySQL Installer has Set a Random Password.
sudo cat /root/.mysql_secret
Or in Installations by Rpm Installer:
sudo grep 'temporary password' /var/log/mysqld.log
If Got “User is Not in Sudoers file” then see: How to Enable sudo
Possibly Check also in your User Home…
If Found then Try this Password to Login!
-
Else Reset the MysQL root Pass.
-
Check if MySQL is Already Started.
Find mysqld PID
ps ax | grep mysqld
Log-In as Super-User with:
sudo su
Or:
su -
If MySQL is Started then Kill mysqld with:
pkill mysqld
Or:
kill -9 [PID]
In Ubuntu/Debian-based also:
service mysql stop
-
Start MySQL Server in Recovery Mode.
mysqld_safe --skip-grant-tables --skip-networking &
If No mysqld_safe because MySQL 5.7.6+ & systemd
-
Then you Can Safely Reset MySQL root Pass.
mysql -u root
use mysql;
UPDATE user SET Password=PASSWORD("[newPass]") WHERE User="root";
exit
Then you should be able to Login as root into MySQL!
-
Recommended MySQL Server Database Secure SetUp