#1045 - Access denied for user 'root'@'localhost' (using password: YES) code example
Example 1: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
sudo service mysql stop
sudo mkdir /var/run/mysqld
sudo chown mysql: /var/run/mysqld
sudo mysqld_safe --skip-grant-tables --skip-networking &
mysql -u root mysql
UPDATE mysql.user SET authentication_string=PASSWORD('YourNewPasswordBuddy'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';
FLUSH PRIVILEGES;
EXIT;
sudo service mysql restart
mysql -u root -p
Example 2: phpMyAdmin access denied message
Open the phpMyAdmin folder.
Open the config.inc.php file with any text editor.
Under “Authentication type and info,” and update the following lines:
On $cfg['Servers'][$i]['auth_type'] = 'config'; replace config for cookie.
On $cfg['Servers'][$i]['AllowNoPassword'] = true; replace true for false.
Example 3: Error 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
sudo mysql -u root -p
Example 4: mysql error 1045
mysql> SELECT Host, User, authentication_string, PASSWORD('forgotten') FROM mysql.user WHERE User='nonexistant';
+-------------+-------------+-------------------------------------------+-------------------------------------------+
| Host | User | authentication_string | PASSWORD('forgotten') |
+-------------+-------------+-------------------------------------------+-------------------------------------------+
| 192.168.0.1 | nonexistant | *AF9E01EA8519CE58E3739F4034EFD3D6B4CA6324 | *70F9DD10B4688C7F12E8ED6C26C6ABBD9D9C7A41 |
| % | nonexistant | *AF9E01EA8519CE58E3739F4034EFD3D6B4CA6324 | *70F9DD10B4688C7F12E8ED6C26C6ABBD9D9C7A41 |
+-------------+-------------+-------------------------------------------+-------------------------------------------+
2 rows in set, 1 warning (0.00 sec)