MySQL root problems (access denied for root user)

98,695

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

  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.

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

Share:
98,695

Related videos on Youtube

Matthew Salsamendi
Author by

Matthew Salsamendi

Updated on September 18, 2022

Comments

  • Matthew Salsamendi
    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
    Matthew Salsamendi about 11 years
    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)
  • Mircea Vutcovici
    Mircea Vutcovici about 11 years
    this means you did not use --skip-grant-tables
  • Matthew Salsamendi
    Matthew Salsamendi about 11 years
    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.
  • Mircea Vutcovici
    Mircea Vutcovici about 11 years
    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;
  • Matthew Salsamendi
    Matthew Salsamendi about 11 years
    I am connecting from localhost to run that command. However, I can't seem to execute that command, even from localhost.
  • Matthew Salsamendi
    Matthew Salsamendi about 11 years
    This is what I get when I do the select statement:
  • Matthew Salsamendi
    Matthew Salsamendi about 11 years
    +-----------+------+------------+ | host | user | grant_priv | +-----------+------+------------+ | localhost | root | Y | | 127.0.0.1 | root | Y | +-----------+------+------------+
  • Qwerty-Space
    Qwerty-Space about 11 years
    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 ";".]
  • Matthew Salsamendi
    Matthew Salsamendi about 11 years
    Here's the result of that: pastebin.com/xxW5q3Xb
  • Qwerty-Space
    Qwerty-Space about 11 years
    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.
  • Matthew Salsamendi
    Matthew Salsamendi about 11 years
    mysql> 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
    Matthew Salsamendi about 11 years
    Formatting got a bit messed up, but yes, it is the correct command.
  • versedi
    versedi about 9 years
    It's not a solution, it's a cause. How to fix it?
  • Deckard
    Deckard about 6 years
    Maybe mysql_upgrade will be the answer? I'm facing the same problem..
  • Fredrick Anyera M
    Fredrick Anyera M almost 5 years
    3. Use this instead ### update user set authentication_string=password('MyNewPass') where user='root';