MySQL root problems (access denied for root user)
Solution 1
Found the solution -- This is caused by updating MySQL from MySQL 5.1 to MySQL 5.5 and moving the authentication schema (the MySQL database itself) along with it. As there are core updates to this schema using it with a 5.5 database simply won't work causing two main bugs: Cannot GRANT privileges as root Mysql users deleted
Solution 2
You can start MySQL with the authentication disabled. From there you can create/delete the administrative account for MySQL.
The details you can find in the MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
-
Shutdown MySQL
-
Start MySQL with:
mysqld --skip-grant-tables --skip-networking
-
In mysql run:
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
For newer MySQL versions:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; GRANT ALL PRIVILEGES ON \*.\* TO 'root'@'localhost' WITH GRANT OPTION;
-
Shutdown MySQL
-
Start MySQL as you usually do.
Solution 3
Try accesing the server with 'root'@'127.0.0.1' which is diferent from 'root'@'localhost'. Then issue a command to create the user 'root'@'localhost' and grant all privileges to it
Related videos on Youtube
Matthew Salsamendi
Updated on September 18, 2022Comments
-
Matthew Salsamendi over 1 year
I've having some very weird issues with my MySQL (5.5) root user. I'm trying to allow an external host to access the root user, but it seems as though my root@localhost does not have "GRANT OPTION" to the local databases! I think the issue at this point is caused by the fact that I think I have two root@localhost users, both with different grant rules, but I can't figure out how to get back into my install.
I've already tried deleting the root user and recreating it (I think), resetting the root users password (modifying the mysql database itself)
I can't get into the root account using the password I've always specified but rather an alternate password, which I don't even know how I got... this alternate user is the one that doesn't seem to have full root permissions, yet is still called root.
--SOLUTION POSTED BELOW--
-
Matthew Salsamendi about 11 yearsDid that and still getting mysql> GRANT ALL ON . TO 'root'@'*********' IDENTIFIED BY '************************************'; ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
-
Mircea Vutcovici about 11 yearsthis means you did not use
--skip-grant-tables
-
Matthew Salsamendi about 11 yearsI actually did use --skip-grant-tables as instructed, and logged in and made the changes as requested. After restarting MySQL normally we still cannot grant granting powers to all databases using the root user.
-
Mircea Vutcovici about 11 yearsyou need to connect from localhost. If you want to connect remotely, you have to run also:
GRANT ALL PRIVILEGES ON . TO 'root'@'%' WITH GRANT OPTION;
-
Matthew Salsamendi about 11 yearsI am connecting from localhost to run that command. However, I can't seem to execute that command, even from localhost.
-
Matthew Salsamendi about 11 yearsThis is what I get when I do the select statement:
-
Matthew Salsamendi about 11 years+-----------+------+------------+ | host | user | grant_priv | +-----------+------+------------+ | localhost | root | Y | | 127.0.0.1 | root | Y | +-----------+------+------------+
-
Qwerty-Space about 11 yearsThese roots clearly do not have different grant_privs so it seems like this wasn't the problem. I suggest you give more detail. Maybe output of "select * from user where user = 'root'\G". [Note the "\G" rather than ";".]
-
Matthew Salsamendi about 11 yearsHere's the result of that: pastebin.com/xxW5q3Xb
-
Qwerty-Space about 11 yearsAccording to this, local root has all privileges, exactly as is should. So, you "should" be able to create a remote root user with: "GRANT ALL PRIVILEGES ON *.* TO root@otherhost IDENTIFIED BY 'secret' WITH GRANT OPTION;". Of course, replace "otherhost" and "secret" as appropriate. Maybe this is what you tried from the beginning but just need to check.
-
Matthew Salsamendi about 11 yearsmysql> GRANT ALL ON . to 'root'@'50.77.114.11' IDENTIFIED BY 'secret' WITH GRANT OPTION; ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
-
Matthew Salsamendi about 11 yearsFormatting got a bit messed up, but yes, it is the correct command.
-
versedi about 9 yearsIt's not a solution, it's a cause. How to fix it?
-
Deckard about 6 yearsMaybe
mysql_upgrade
will be the answer? I'm facing the same problem.. -
Fredrick Anyera M almost 5 years3. Use this instead ### update user set authentication_string=password('MyNewPass') where user='root';