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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

参考答案:

正常状态:

[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


相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
16天前
|
Ubuntu 关系型数据库 MySQL
mysql8.0安装初始化不需要设定root密码?
uubntu 的mysql安装完成后无法设定root密码
131 10
|
8月前
|
Cloud Native 关系型数据库 分布式数据库
阿里云牵手海亮科技,共建“教育科技数据库创新应用中心”
海亮科技选择引入阿里云PolarDB开源分布式版(PolarDB for Xscale)数据库,不仅能解决海亮科技数据库业务中面临的可靠性、稳定性问题,也为海亮科技业务的高速发展提供了更好的灵活性和可扩展性。
|
6月前
|
存储 关系型数据库 MySQL
【赵渝强老师】解决MySQL丢失root用户密码
本文介绍了MySQL数据库中用户密码存储的变化,以及如何通过特殊方法重置root用户的密码。从MySQL 5.7版本开始,密码字段由“password”改为“authentication_string”。文章详细列出了重置密码的步骤,并提供了相关代码示例和视频教程。
209 0
|
8月前
|
Cloud Native 关系型数据库 分布式数据库
阿里云牵手海亮科技,共建“教育科技数据库创新应用中心”
近日,阿里云与世界500强旗下、国内领先的教育服务提供商海亮科技集团(以下简称“海亮科技”)达成合作,联合成立“教育科技数据库创新应用中心”。双方将充分整合优势资源,共同推进教育科技领域的数据库技术研究和国产数据库的应用与发展。
202 8
|
9月前
|
SQL 关系型数据库 MySQL
mysql密码错误-ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using passwor:yes)
这篇文章提供了解决MySQL数据库"Access denied for user 'root'@'localhost' (using password: YES)"错误的方法,通过跳过密码验证、修改root密码,然后重启服务来解决登录问题。
mysql密码错误-ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using passwor:yes)
|
9月前
|
安全 关系型数据库 MySQL
在Linux中,如何重置 mysql root 密码?
在Linux中,如何重置 mysql root 密码?
|
9月前
|
安全 关系型数据库 MySQL
MySQL非root安装-初始化数据库时unknown variable ‘defaults-file=**/my.cnf‘
解决安装过程中出现的问题通常需要仔细地检查错误日志、配置文件和执行命令,保证各项配置设置的精确无误是顺利完成安装的关键。通过上述的步骤分析和解决方案,非root用户安装MySQL时遇到"unknown variable 'defaults-file=**/my.cnf'"的问题应该可以得到妥善的解决。
860 0
|
9月前
|
安全 关系型数据库 MySQL
如何在 MySQL 中导入和导出数据库以及重置 root 密码
如何在 MySQL 中导入和导出数据库以及重置 root 密码
130 0
|
22天前
|
负载均衡 算法 关系型数据库
大数据大厂之MySQL数据库课程设计:揭秘MySQL集群架构负载均衡核心算法:从理论到Java代码实战,让你的数据库性能飙升!
本文聚焦 MySQL 集群架构中的负载均衡算法,阐述其重要性。详细介绍轮询、加权轮询、最少连接、加权最少连接、随机、源地址哈希等常用算法,分析各自优缺点及适用场景。并提供 Java 语言代码实现示例,助力直观理解。文章结构清晰,语言通俗易懂,对理解和应用负载均衡算法具有实用价值和参考价值。
大数据大厂之MySQL数据库课程设计:揭秘MySQL集群架构负载均衡核心算法:从理论到Java代码实战,让你的数据库性能飙升!
|
2月前
|
关系型数据库 MySQL Java
【YashanDB知识库】原生mysql驱动配置连接崖山数据库
【YashanDB知识库】原生mysql驱动配置连接崖山数据库
【YashanDB知识库】原生mysql驱动配置连接崖山数据库

热门文章

最新文章