Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 恢复我的根用户';s在MariaDB上的DBA权限_Mysql_Sql_Linux_Centos_Mariadb - Fatal编程技术网

Mysql 恢复我的根用户';s在MariaDB上的DBA权限

Mysql 恢复我的根用户';s在MariaDB上的DBA权限,mysql,sql,linux,centos,mariadb,Mysql,Sql,Linux,Centos,Mariadb,我不小心从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) 有人经历过

我不小心从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)
有人经历过这种情况吗?

停止MariaDb服务器

sudo systemctl stop mariadb

未经许可重新启动数据库检查-

sudo mysqld\u safe--跳过授权表--跳过网络&

mysql-u root
输入密码

重新加载格兰特表

Mariadb[MYSQL]>刷新权限

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
我希望这对你有用。它确实对我有用


您可以在

上探索答案主机名的通配符也包括localhost是错误的假设,因此尝试通过套接字(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)
georg@mozart:~/mariadb$ mysql -uroot -e"select current_user()\G"
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
使用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
georg@mozart:~/mariadb$ sudo mysql -uroot -e"select current_user()\G"
*************************** 1. row ***************************
current_user(): root@localhost
从MariaDB服务器10.4(Posix平台)开始,根用户的默认身份验证方法(通过本地主机连接时)通过unix_套接字插件进行。这允许root@localhost只要尝试从操作系统根用户帐户拥有的进程登录,用户就可以通过套接字系统变量定义的本地Unix套接字文件不使用密码登录:

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用户身份正常登录将失败:

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)
georg@mozart:~/mariadb$ mysql -uroot -e"select current_user()\G"
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
以root(sudo)身份运行时,登录按预期工作:

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
georg@mozart:~/mariadb$ sudo mysql -uroot -e"select current_user()\G"
*************************** 1. row ***************************
current_user(): root@localhost

有关如何重置密码的详细信息,请参阅dba.stackexchange。@Dave未成功,提示是密码恢复,我知道密码。我的问题是,我的根用户没有DBA,但没有权限,这就是我要还原的。我想“碰撞”这个问题,因为我遇到了完全相同的问题。您使用的服务器版本是什么?我还怀疑在发送GRANT语句时是否返回了上面的错误消息,它看起来更像是从命令行客户端进行的登录尝试。人们通常不使用
GRANT
CREATE USER
语句,而是通过直接修改系统表来更改数据库配置。在MariaDB的最新版本中,这是不可能的,因为这些表变成了不可插入的视图。