Sunday, September 10, 2017

MariaDB: Access denied for user 'root'@'%' to your database


I used to access the root user in MySQL just fine. But recently, I am no longer able to.
I am able to login fine :
 mysql -u root -p
Here is the mysql status after login :
mysql> status
--------------
mysql  Ver 14.14 Distrib 5.5.28, for debian-linux-gnu (i686) using readline 6.2

Connection id:      37
Current database:   
Current user:       root@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.5.28-0ubuntu0.12.04.3 (Ubuntu)
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:        /var/run/mysqld/mysqld.sock
Uptime:         4 min 16 sec

Threads: 1  Questions: 112  Slow queries: 0  Opens: 191  
Flush tables: 1  Open tables:  6  Queries per second avg: 0.437
--------------

But when I want to do any action, such as :
 
mysql> CREATE DATABASE moyennegenerale;
ERROR 1044 (42000): Access denied for user 'root'@'%' to database 'moyennegenerale'

I understand % is used to signify any host , but my status clearly states localhost. Does somebody have an idea of what might be going on?
 

 
Answer
___________________________________
 




I know what you did. Do this:
 
SELECT `User`, `Grant_priv` FROM `mysql`.`user` WHERE `User` = 'root';

You will probably notice it returns a 'N' for Grant_priv. So do this:
 
UPDATE `mysql`.`user` SET `Grant_priv` = 'Y' WHERE `User` = 'root'; 
 
FLUSH PRIVILEGES; 
 
SELECT `User`, `Grant_priv` FROM `mysql`.`user`;
 
And walla! Hope that helps.