5

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--

6 Answers 6

6

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

  1. Shutdown MySQL

  2. Start MySQL with: mysqld --skip-grant-tables --skip-networking

  3. 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;
    
  4. Shutdown MySQL

  5. Start MySQL as you usually do.

5
  • Did that and still getting mysql> GRANT ALL ON . TO 'root'@'*********' IDENTIFIED BY '************************************'; ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) Mar 2, 2013 at 0:37
  • this means you did not use --skip-grant-tables Mar 2, 2013 at 1:06
  • I 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. Mar 2, 2013 at 1:13
  • you 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; Mar 2, 2013 at 1:21
  • 1
    I am connecting from localhost to run that command. However, I can't seem to execute that command, even from localhost. Mar 2, 2013 at 1:23
2

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

2
  • 7
    It's not a solution, it's a cause. How to fix it?
    – versedi
    Mar 25, 2015 at 8:13
  • Maybe mysql_upgrade will be the answer? I'm facing the same problem..
    – Deckard
    Apr 2, 2018 at 5:47
1

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

0

You should remove the extra root@localhost entry. This can be done either with "--skip-grant-tables" as suggested by Mircea Vutcovici or in a normal session (local or remote) if you can still access as root.

Try something like this:

#get to admin tables
use mysql
#confirm the differences for the root entries
select host, user, grant_priv from user where user = 'root'; 
#adjust as needed
delete from user where user = 'root' and host = 'localhost' and grant_priv = 'N';
#commit
flush privileges;

Update: According to the output you showed for the select test, it doesn't appear that you have a problem with multiple roots with different grant_privs. Therefore, if the advice given by Mircea Vutcovici doesn't fix your problem, I might guess that the real problem does lie with root privs. Maybe you're doing something else incorrectly like trying to connect to the wrong host or using a password saved in a config file (.my.cnf). In other words, you might need to be more specific.

7
  • This is what I get when I do the select statement: Mar 3, 2013 at 7:35
  • +-----------+------+------------+ | host | user | grant_priv | +-----------+------+------------+ | localhost | root | Y | | 127.0.0.1 | root | Y | +-----------+------+------------+ Mar 3, 2013 at 7:36
  • These 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 ";".]
    – igelkott
    Mar 3, 2013 at 15:38
  • Here's the result of that: pastebin.com/xxW5q3Xb Mar 6, 2013 at 4:26
  • According 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.
    – igelkott
    Mar 6, 2013 at 19:31
0

Typing SHOW GRANTS FOR 'root'@'localhost'; showed me some obscured password, so I logged into mysql of that system using HeidiSQL on another system (using root as the username and the corresponding password) and typed
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'thepassword' WITH GRANT OPTION;

and it worked when I went back to the system and logged on using
mysql -uroot -pthepassword;

0

Here are the few steps that i followed on the windows system

  1. Login to the mysql using the user that has Privileges (from the account by which you have deleted the permission for the root).
  2. Choose the database mysql using the command use mysql;
  3. Fire the following command to update the user.

UPDATE mysql.user SET PASSWORD=PASSWORD('MyNewPass') WHERE USER='root';

  1. FLUSH PRIVILEGES;

  2. GRANT ALL ON *.* TO 'root'@'localhost';

  3. logout from the user and then login to the root using the new password above steps worked for me

1
  • 3. Use this instead ### update user set authentication_string=password('MyNewPass') where user='root'; May 8, 2019 at 14:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .