老男孩教育每日一题-第113天-mysql数据库中管理员用户(root@localhost)被误删除,怎么恢复?

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

参考答案:

正常状态:

[root@web01 data]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 75
Server version: 5.6.34 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user,host from mysql.user;
+-----------+--------------------------+
| user      | host                     |
+-----------+--------------------------+
| root      | 127.0.0.1                |
| wordpress | 172.16.1.0/255.255.255.0 |
| root      | ::1                      |
|           | localhost                |
| root      | localhost                |
|           | web01                    |
| root      | web01                    |
+-----------+--------------------------+
7 rows in set (0.00 sec)

管理员用户被误删除后:

mysql> drop user root@localhost;
Query OK, 0 rows affected (0.07 sec)

mysql> select user,host from mysql.user;
+-----------+--------------------------+
| user      | host                     |
+-----------+--------------------------+
| root      | 127.0.0.1                |
| wordpress | 172.16.1.0/255.255.255.0 |
| root      | ::1                      |
|           | localhost                |
|           | web01                    |
| root      | web01                    |
+-----------+--------------------------+
6 rows in set (0.00 sec)

解决:

需要使用root@127.0.0.1用户登录系统(无密码),再创建root@localhost

[root@web01 data]# mysql -h 127.0.0.1 -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 80
Server version: 5.6.34 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> 
mysql> select user,host,password from mysql.user;
+-----------+--------------------------+-------------------------------------------+
| user      | host                     | password                                  |
+-----------+--------------------------+-------------------------------------------+
| root      | web01                    |                                           |
| root      | 127.0.0.1                |                                           |
| root      | ::1                      |                                           |
|           | localhost                |                                           |
|           | web01                    |                                           |
| wordpress | 172.16.1.0/255.255.255.0 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+--------------------------+-------------------------------------------+
6 rows in set (0.00 sec)

mysql> grant all on *.* to root@localhost identified by '123456' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

恢复正常

[root@web01 data]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 81
Server version: 5.6.34 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user,host from mysql.user;
+-----------+--------------------------+
| user      | host                     |
+-----------+--------------------------+
| root      | 127.0.0.1                |
| wordpress | 172.16.1.0/255.255.255.0 |
| root      | ::1                      |
|           | localhost                |
| root      | localhost                |
|           | web01                    |
| root      | web01                    |
+-----------+--------------------------+
7 rows in set (0.00 sec)

备注

今天是每日一题陪伴大家的第113天期待你的进步

对于题目和答案的任何疑问,请在博客评论区留言
往期题目索引

http://lidao.blog.51cto.com/3388056/1914205


本文转自 李导 51CTO博客,原文链接:http://blog.51cto.com/lidao/1959488


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
28天前
|
关系型数据库 MySQL 数据库
mysql中如何将默认用户名root改成其他?
mysql中如何将默认用户名root改成其他?
22 0
|
1月前
|
关系型数据库 MySQL 数据库
MySQL忘记root密码、远程无法连接的解决方法
MySQL忘记root密码、远程无法连接的解决方法
|
3月前
|
Ubuntu 关系型数据库 MySQL
百度搜索:蓝易云【ubuntu下Mysql安装与root密码重置教程】
请注意,以上步骤是针对Ubuntu系统的。如果你使用的是其他Linux发行版,请相应地调整命令。
110 1
|
4月前
|
数据安全/隐私保护 时序数据库
InfluxData【部署 03】时序数据库 InfluxDB 离线安装配置使用(下载+安装+端口绑定+管理员用户创建+开启密码认证+开机自启配置)完整流程实例分享
InfluxData【部署 03】时序数据库 InfluxDB 离线安装配置使用(下载+安装+端口绑定+管理员用户创建+开启密码认证+开机自启配置)完整流程实例分享
128 0
|
23天前
|
SQL 关系型数据库 数据库
OceanBase数据库常见问题之录入租户管理员密码时,提示密码检验失败如何解决
OceanBase 是一款由阿里巴巴集团研发的企业级分布式关系型数据库,它具有高可用、高性能、可水平扩展等特点。以下是OceanBase 数据库使用过程中可能遇到的一些常见问题及其解答的汇总,以帮助用户更好地理解和使用这款数据库产品。
|
1月前
|
缓存 关系型数据库 MySQL
MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password: YES)无法打开的解决方法
MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password: YES)无法打开的解决方法
|
2月前
|
关系型数据库 MySQL 数据库
连接mysql报Access denied for user 'root'@'localhost'错误的解决办法
连接mysql报Access denied for user 'root'@'localhost'错误的解决办法
|
2月前
|
关系型数据库 MySQL 数据库
MySql修改root密码
MySql修改root密码
21 0
|
4月前
|
关系型数据库 MySQL Linux
MySQL【部署 02】Linux 非 root 用户部署 mysql-5.7.28 设置开机启动及问题汇总(含云盘资源)
MySQL【部署 02】Linux 非 root 用户部署 mysql-5.7.28 设置开机启动及问题汇总(含云盘资源)
70 0
|
4月前
|
关系型数据库 MySQL Linux
MySQL【部署 01】Linux root 用户部署 mysql-5.7.28 及 not allowed to connect to this MySQL server 和中文乱码问题处理
MySQL【部署 01】Linux root 用户部署 mysql-5.7.28 及 not allowed to connect to this MySQL server 和中文乱码问题处理
49 0