ERROR 1044 (42000): Access denied for 'root' With All Privileges
Asked Answered
S

4

29

I have strange error. I am logged in local Mysql as root via command line. After creating database:

create database some_db;

Then giving privileges to some user:

grant all privileges on some_db.* to some_user@'localhost' identified by 'password';

This is giving error:

ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'some_db'

The permissions for the root(show grants;) shows:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*8919C53DC7A4DFBF3F8584382E96463583EB7FDA' 

I am also making sure i am logged in as root:

select current_user();

And this confirms that i am logged in as 'root'@'localhost'

I have created database and assigned user multiple times and never had an issue. Why i am unable assign user to the database created by root while logged in as root?

p.s. from other posts, i am thinking the issue may be caused due to some strange users

select host, user from mysql.user;

Some users that i have not added but does show up:

 MY_COMPuTER_name.local |       ''
 MY_COMPuTER_name.local |     root

I tried to delete these users

drop user 'root'@'MY_COMPuTER_name.local';
drop user ''@'MY_COMPuTER_name.local';

However, while it states query run successful, the users are not dropped even after flush privileges. Why i am unable delete users? Any help is much appricated

Silvey answered 11/2, 2014 at 22:51 Comment(4)
You haven't quoted the user name in you first GRANT statementSumpter
you seem to be missing the GRANT OPTION. For instance, my root SHOW GRANTS says: GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY ... WITH GRANT OPTION. That last part is kinda important to be able to GRANT privileges ;)Projection
Thank You for suggestions. Perhaps, those are good to have but no exactly necessary and it doesn't solve the problem. Thank you againSilvey
As @Sumpter and @ Wrikken indicate, then "grant" option is a special case that IS NOT INCLUDED in the "ALL PRIVILEGES" clause.Abana
I
57

First, Identify the user you are logged in as:

 select user();
 select current_user();

The result for the first command is what you attempted to login as, the second is what you actually connected as. Confirm that you are logged in as root@localhost in mysql.

Grant_priv to root@localhost. Here is how you can check.

mysql> SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user;
+-----------+------------------+-------------------------------------------+------------+------------+
| host      | user             | password                                  | Grant_priv | Super_priv |
+-----------+------------------+-------------------------------------------+------------+------------+
| localhost | root             | ***************************************** | N          | Y          |
| localhost | debian-sys-maint | ***************************************** | Y          | Y          |
| localhost | staging          | ***************************************** | N          | N          |
+-----------+------------------+-------------------------------------------+------------+------------+

You can see that the Grant_priv is set to N for root@localhost. This needs to be Y. Below is how to fixed this:

UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
FLUSH PRIVILEGES;
GRANT ALL ON *.* TO 'root'@'localhost';

I logged back in, it was fine.

Izaguirre answered 13/2, 2014 at 4:1 Comment(6)
Vow...this is awesome! Thank You. this solved the problems. I didn't know there are two type grant permission and how to to see them and than set them. Good learning. Thank you so mushSilvey
under mysql 5.5.37 ubuntu 12.04 LTS I am seeing all things according this answer to be correct and still getting the ERROR 1044 (42000) Access denied for user 'root'@'localhost' to database ...Pistil
no - the workaround was to make sure no remains of the original installation in /etc/ and /var/lib/mysql where used. The original installation was without any root user and done by my hosting provider. Adding the root user and setting permissions manually did not help! I had to reinstall from scratch with no /etc and /var/lib/mysql content and things ran smoothely from there ... I will have to figure our what to do with all those users that my installation expects from me ...Pistil
@WolfgangFahl can you post it as a separate question and the problem you are facing? so that i can get a clear idea about your problem! and others too will help you..!Izaguirre
@Armarnath: #23798719Pistil
serverfault.com/questions/597814/…Pistil
S
1

The reason i could not delete some of the users via 'drop' statement was that there is a bug in Mysql http://bugs.mysql.com/bug.php?id=62255 with hostname containing upper case letters. The solution was running following query:

DELETE FROM mysql.user where host='Some_Host_With_UpperCase_Letters';

I am still trying to figure the other issue where the root user with all permissions are unable to grant privileges to new user for particular database

Silvey answered 13/2, 2014 at 3:33 Comment(0)
S
1

If you get an error 1044 (42000) when you try to run SQL commands in MySQL (which installed along XAMPP server) cmd prompt, then here's the solution:

  1. Close your MySQL command prompt.

  2. Open your cmd prompt (from Start menu -> run -> cmd) which will show: C:\Users\User>_

  3. Go to MySQL.exe by Typing the following commands:

C:\Users\User>cd\ C:\>cd xampp C:\xampp>cd mysql C:\xxampp\mysql>cd bin C:\xampp\mysql\bin>mysql -u root

  1. Now try creating a new database by typing:

    mysql> create database employee;
    

    if it shows:

    Query OK, 1 row affected (0.00 sec)
    mysql>
    

    Then congrats ! You are good to go...

Smaragdite answered 3/8, 2014 at 11:10 Comment(0)
N
-1

Try to comment string "sql-mode=..." in file my.cnf and than restart mysql.

Nympho answered 19/6, 2020 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.