gpt4 book ai didi

mysql - 恢复MySQL的用户根目录

转载 作者:可可西里 更新时间:2023-11-01 08:02:10 25 4
gpt4 key购买 nike

我无意中删除了本地安装的MySQL的根用户,该MySQL运行在OSX上。没有创建其他用户返回MySQL。任何人都知道如何在mysql中恢复根用户。

最佳答案

我的方法又快又脏
请具有系统管理员权限的人员执行以下操作:
在[mysqld]部分的/etc/mysql/mysql.conf.d/mysqld.cnf中添加'skip grant tables'。
重启mysql
键入没有密码的mysql并按enter
运行此:

DELETE FROM mysql.user 
WHERE user = 'root'
AND host = 'localhost';

INSERT INTO `user` (
`Host`, `User`, `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`, `Event_priv`, `Trigger_priv`,
`Create_tablespace_priv`, `ssl_type`, `ssl_cipher`,
`x509_issuer`, `x509_subject`, `max_questions`,
`max_updates`, `max_connections`, `max_user_connections`,
`plugin`, `authentication_string`, `password_expired`,
`password_last_changed`, `password_lifetime`, `account_locked`
) 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', 'Y', 'Y', 'Y', '', '', '', '',
0, 0, 0, 0, 'mysql_native_password',
'*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B', 'N',
'2018-07-20 14:47:59', NULL, 'N'
);

退出mysql
从[mysqld]部分下的 /etc/mysql/mysql.conf.d/mysqld.cnf中删除“skip grant tables”
重启mysql
就这些!

关于mysql - 恢复MySQL的用户根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53313604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com