anish samant
anish samant

Reputation: 193

You are using mariadb as an anonymous user

All the privileges have been denied and all my databases seem to have been deleted. I get the error mentioned in the subject when I try to change the password. Initially there was no password set and this behaviour started after executing the following command

update mysql.user set password=password('newpass') where user='root';

I enter mysql using:

mysql -u root

Every command I try to execute gives me access denied error. I tried surfing on google but did not get a solution to solve the issue.

Upvotes: 8

Views: 13133

Answers (2)

Alex
Alex

Reputation: 1020

> select version();
+----------------------------------+
| version()                        |
+----------------------------------+
| 10.1.48-MariaDB-0ubuntu0.18.04.1 |
+----------------------------------+



# systemctl stop mariadb
# mysqld --skip-grant-tables  &
# mysql

>  flush privileges;
> update mysql.user  
       set authentication_string=password('789'),  
       plugin='mysql_native_password'  
       where user='root' and host='localhost';
>exit

# kill -15 $(ps aux | grep mysqld | grep -v grep | awk '{print $2}')
# systemctl start mariadb
# mysql -u root -p
Enter password: 789

MariaDB [(none)]> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+

If mariadb >=10.2 then use ALTER USER ( alter user announcement)

Upvotes: -1

Goufalite
Goufalite

Reputation: 2363

You must set the plugin of the user too, and flush privileges everytime

> update mysql.user set password=password('newpass') where user='root';
> flush privileges;
> update mysql.user set plugin='mysql_native_password' where user='root';
> flush privileges;

Then check you are not using an anonymous user when the database instance starts: in your /etc/my.cnf remove/comment any line which looks like this

skip-grant-tables #comment with #

And restart the database

service <db> restart

Upvotes: 22

Related Questions