MySQL 5.7 误删管理员root%’localhost’账户

2023年 4月 29日 19.7k 0

MySQL 5.7 误删管理员root%'localhost'账户的解决方法。 1)停止数据库 kill Mysql进程 2)在加上 --skip-grant-tables启动mysql 进程加粗样式 其中--skip-grant-tables意思是启动MySQL 服务的时候跳过权限表

MySQL 5.7 误删管理员root%'localhost'账户的解决方法。

1)停止数据库kill Mysql进程

2)在加上 --skip-grant-tables启动mysql 进程加粗样式其中--skip-grant-tables意思是启动MySQL 服务的时候跳过权限表认证。启动后,连接到MySQL 的root 将不需要口令cd /mysqldata/mysql/bin./mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --skip-grant-tables&

3)用空密码的root 用户连接到MySQL,并且更改root 口令mysql -uroot -p use mysql;insert into user set user='root',ssl_cipher='',x509_issuer='',x509_subject='';flush privileges;GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'mN6WT8c#' WITH GRANT OPTION; flush privileges;

4)此时查看新添加用户的权限mysql> select * from mysql.user where user='root'\G;*************************** 1. row ***************************                  Host: localhost                  User: root          Select_priv: Y          Insert_priv: Y          Update_priv: Y          Delete_priv: Y          Create_priv: Y            Drop_priv: Y          Reload_priv: Y        Shutdown_priv: Y          Process_priv: Y            File_priv: Y            Grant_priv: Y      References_priv: Y            Index_priv: Y            Alter_priv: Y          Show_db_priv: Y            Super_priv: Y Create_tmp_table_priv: Y      Lock_tables_priv: Y          Execute_priv: Y      Repl_slave_priv: Y      Repl_client_priv: Y      Create_view_priv: Y        Show_view_priv: Y  Create_routine_priv: Y    Alter_routine_priv: Y      Create_user_priv: Y            Event_priv: Y          Trigger_priv: YCreate_tablespace_priv: Y              ssl_type:             ssl_cipher:           x509_issuer:           x509_subject:         max_questions: 0          max_updates: 0      max_connections: 0  max_user_connections: 0                plugin: mysql_native_password authentication_string: *A1027271824AD76D2BBEED42D431EF9273BB492A      password_expired: N password_last_changed: 2019-07-11 16:29:23    password_lifetime: NULL        account_locked: N*************************** 2. row ***************************                  Host: %                  User: root          Select_priv: Y          Insert_priv: Y          Update_priv: Y          Delete_priv: Y          Create_priv: Y            Drop_priv: Y          Reload_priv: Y        Shutdown_priv: Y          Process_priv: Y            File_priv: Y            Grant_priv: N      References_priv: Y            Index_priv: Y            Alter_priv: Y          Show_db_priv: Y            Super_priv: Y Create_tmp_table_priv: Y      Lock_tables_priv: Y          Execute_priv: Y      Repl_slave_priv: Y      Repl_client_priv: Y      Create_view_priv: Y        Show_view_priv: Y  Create_routine_priv: Y    Alter_routine_priv: Y      Create_user_priv: Y            Event_priv: Y          Trigger_priv: YCreate_tablespace_priv: Y              ssl_type:             ssl_cipher:           x509_issuer:           x509_subject:         max_questions: 0          max_updates: 0      max_connections: 0  max_user_connections: 0                plugin: mysql_native_password authentication_string: *A1F1CB851D62F002C09A0C9C4A76262473432F55      password_expired: N password_last_changed: 2019-07-04 16:55:40    password_lifetime: NULL        account_locked: N2 rows in set (0.00 sec)

ERROR: No query specified

5)重启mysql服务cd /mysqldata/mysql/bin[root@558idc bin]# ./mysqladmin -uroot -p shutdown输入密码:

或者kill Mysql进程    [root@558idc /]# cd /mysqldata/mysql/bin    [root@558idc bin]# ./mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论