恢复我的根用户在mariadb上的dba权限

odopli94  于 2021-07-24  发布在  Java
关注(0)|答案(2)|浏览(344)

我不小心从mariadb中删除了我唯一用户的dba特权,现在我不能使用我的银行,我也无法使用linux shell centos 7恢复特权。
我试过的命令:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

退货:


# 1045 - Access denied for user 'root'@'localhost' (using password: YES)

有人经历过吗?

cfh9epnr

cfh9epnr1#

停止mariadb服务器 sudo systemctl stop mariadb 在没有权限检查的情况下重新启动数据库-更多
sudo mysqld_safe --skip-grant-tables --skip-networking & mysql -u root 输入密码
重新加载grant表 Mariadb[MYSQL]> FLUSH PRIVILEGES ```
insert into user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv, Create_view_priv, Show_view_priv, Create_routine_priv, Alter_routine_priv, Create_user_priv, ssl_type, ssl_cipher, x509_issuer, x509_subject, max_questions, max_updates, max_connections, max_user_connections)
values('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','','0','0','0','0');

然后重新启动数据库 `sudo systemctl start mariadb` 我希望这对你有用。它确实对我有用。
您可以在mariadb上探索关于授予特权的答案
dced5bon

dced5bon2#

错误的假设是主机名的通配符还包括localhost,因此尝试通过socket(localhost)连接将失败:

mysql> create user 'foo'@'%' identified by 'bar';
Query OK, 0 rows affected (0,01 sec)

$mysql -ufoo -pbar -e"select current_user"
ERROR 1045 (28000): Access denied for user 'foo'@'localhost' (using password: YES)

使用localhost创建用户时,一切正常:

mysql> create user 'foo'@'localhost' identified by 'bar';
Query OK, 0 rows affected (0,01 sec)

$ mysql -ufoo -pbar -e"select current_user\G"

***************************1. row***************************

current_user: foo@localhost

同样从mariadb server 10.4(posix平台)开始,根用户的默认身份验证方法(通过localhost连接时)通过unix\u socket插件进行。这允许root@localhost 用户无需密码即可通过socket系统变量定义的本地unix socket文件登录,只要尝试从操作系统根用户帐户拥有的进程登录:

mysql -e"show grants for root@localhost\G"

***************************1. row***************************

Grants for root@localhost: GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED VIA mysql_native_password USING 'invalid' OR unix_socket WITH GRANT OPTION

因此以root身份正常登录将失败:

georg@mozart:~/mariadb$ mysql -uroot -e"select current_user()\G"
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

以root(sudo)身份运行时,登录按预期工作:

georg@mozart:~/mariadb$ sudo mysql -uroot -e"select current_user()\G"

***************************1. row***************************

current_user(): root@localhost

相关问题