I accidentally removed the DBA privileges of my only user from mariadb and now I can’t use my bank and I was also unable to restore the privileges using the Linux SHELL CentOS 7.
Command I tried:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
return:
#1045 - Access denied for user 'root'@'localhost' (using password: YES)
Has anyone ever experienced this?
2
Answers
Stop MariaDb server
sudo systemctl stop mariadb
Restart DB without permission checking – more
sudo mysqld_safe --skip-grant-tables --skip-networking &
mysql -u root
enter passwordreload the grant tables
Mariadb[MYSQL]> FLUSH PRIVILEGES
Then restart database
sudo systemctl start mariadb
I hope this works for you. it did work for me.
You can explore answers on Grant privileges on MariaDB
It’s a wrong assumption that the wildcard for hostname also includes localhost, so an attempt to connect via socket (localhost) will fail:
When creating the user with localhost, everything works as expected:
Also beginning with MariaDB Server 10.4 (Posix platforms) the default authentication method for the root user (when connecting via localhost) happens via unix_socket plugin. This allows the root@localhost user to login without a password via the local Unix socket file defined by the socket system variable, as long as the login is attempted from a process owned by the operating system root user account:
So a normal login as root will fail:
While running as root (sudo) login works as expected: