MySQL - ERROR 1045 - Access denied
MysqlLinuxPasswordsMysql Error-1045Mysql Problem Overview
In some way I have managed to get this error when I try to access into MySQL via the command line:
[root@localhost ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
I have tried resetting the password without any luck using this HowTo.
I have uninstalled mysql completley and reinstalled but I still get asked for a password. I have no idea why this is the case!
Can someone please help me get a default install of MySQL.
Environment
Fedora Core 10, Full Root Access, Apache and PHP installed
Thank you for any help!!
EDIT
To all those that would like to save themselves a few hours of "blood coughing" - when you uninstall MySQl completely delete everything that is left behind. If you don't do this, it will never be a FRESH install.
Mysql Solutions
Solution 1 - Mysql
If you actually have set a root password and you've just lost/forgotten it:
-
Stop MySQL
-
Restart it manually with the skip-grant-tables option:
mysqld_safe --skip-grant-tables
-
Now, open a new terminal window and run the MySQL client:
mysql -u root
-
Reset the root password manually with this MySQL command:
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
If you are using MySQL 5.7 (check using mysql --version in the Terminal) then the command is:UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
-
Flush the privileges with this MySQL command:
FLUSH PRIVILEGES;
From <http://www.tech-faq.com/reset-mysql-password.shtml>
(Maybe this isn't what you need, Abs, but I figure it could be useful for people stumbling across this question in the future)
Solution 2 - Mysql
Try connecting without any password:
mysql -u root
I believe the initial default is no password for the root account (which should obviously be changed as soon as possible).
Solution 3 - Mysql
use this command to check the possible output
mysql> select user,host,password from mysql.user;
output
mysql> select user,host,password from mysql.user;
+-------+-----------------------+-------------------------------------------+
| user | host | password |
+-------+-----------------------+-------------------------------------------+
| root | localhost | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root | localhost.localdomain | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root | 127.0.0.1 | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| admin | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| admin | % | |
+-------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)
-
In this user admin will not be allowed to login from another host though you have granted permission. the reason is that user admin is not identified by any password.
-
Grant the user admin with password using GRANT command once again
mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED by 'password'
then check the GRANT LIST the out put will be like his
mysql> select user,host,password from mysql.user;
+-------+-----------------------+-------------------------------------------+
| user | host | password |
+-------+-----------------------+-------------------------------------------+
| root | localhost | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root | localhost.localdomain | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root | 127.0.0.1 | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| admin | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| admin | % | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
+-------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)
if the desired user for example user 'admin' is need to be allowed login then use once GRANT command and execute the command.
Now the user should be allowed to login.
Solution 4 - Mysql
The current root password must be empty. Then under "new root password" enter your password and confirm.
Solution 5 - Mysql
I had the same error, but it was because password_expired
was set to Y
. You can fix that issue by following the same approach as the currently accepted answer, but instead executing the MySQL query:
UPDATE mysql.user SET password_expired = 'N' WHERE User='root';
Solution 6 - Mysql
-
Go to mysql console
-
Enter use mysql;
-
UPDATE mysql.user SET Password= PASSWORD ('') WHERE User='root' FLUSH PRIVILEGES; exit PASSWORD ('') is must empty
-
Then go to wamp/apps/phpmyadmin../config.inc.php
-
Find $cfg ['Servers']['$I']['password']='root';
-
Replace the ['password'] with ['your old password']
-
Save the file
-
Restart the all services and goto localhost/phpmyadmin
Solution 7 - Mysql
I could not connect to MySql Administrator. I fixed it by creating another user and assigning all the permissions.
I logged in with that new user and it worked.