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

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

参考答案:

正常状态:

[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


相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
6月前
|
Ubuntu 关系型数据库 MySQL
mysql8.0安装初始化不需要设定root密码?
uubntu 的mysql安装完成后无法设定root密码
396 10
|
Cloud Native 关系型数据库 分布式数据库
阿里云牵手海亮科技,共建“教育科技数据库创新应用中心”
海亮科技选择引入阿里云PolarDB开源分布式版(PolarDB for Xscale)数据库,不仅能解决海亮科技数据库业务中面临的可靠性、稳定性问题,也为海亮科技业务的高速发展提供了更好的灵活性和可扩展性。
|
存储 关系型数据库 MySQL
MySQL 忘记root密码解决方案
【7月更文挑战第19天】
1838 4
|
Cloud Native 关系型数据库 分布式数据库
阿里云牵手海亮科技,共建“教育科技数据库创新应用中心”
近日,阿里云与世界500强旗下、国内领先的教育服务提供商海亮科技集团(以下简称“海亮科技”)达成合作,联合成立“教育科技数据库创新应用中心”。双方将充分整合优势资源,共同推进教育科技领域的数据库技术研究和国产数据库的应用与发展。
289 8
|
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)
|
存储 关系型数据库 MySQL
基于python django 医院管理系统,多用户功能,包括管理员、用户、医生,数据库MySQL
本文介绍了一个基于Python Django框架开发的医院管理系统,该系统设计了管理员、用户和医生三个角色,具备多用户功能,并使用MySQL数据库进行数据存储和管理。
559 4
基于python django 医院管理系统,多用户功能,包括管理员、用户、医生,数据库MySQL
|
存储 关系型数据库 MySQL
【赵渝强老师】解决MySQL丢失root用户密码
本文介绍了MySQL数据库中用户密码存储的变化,以及如何通过特殊方法重置root用户的密码。从MySQL 5.7版本开始,密码字段由“password”改为“authentication_string”。文章详细列出了重置密码的步骤,并提供了相关代码示例和视频教程。
361 0
|
安全 关系型数据库 MySQL
在Linux中,如何重置 mysql root 密码?
在Linux中,如何重置 mysql root 密码?
|
SQL 关系型数据库 MySQL
云服务器 ECS产品使用问题之出现“1044 - Access denied for user ‘root‘@‘%‘ to database ‘数据库名称‘”这样的错误,该怎么办
云服务器ECS(Elastic Compute Service)是各大云服务商阿里云提供的一种基础云计算服务,它允许用户租用云端计算资源来部署和运行各种应用程序。以下是一个关于如何使用ECS产品的综合指南。
|
安全 关系型数据库 MySQL
MySQL非root安装-初始化数据库时unknown variable ‘defaults-file=**/my.cnf‘
解决安装过程中出现的问题通常需要仔细地检查错误日志、配置文件和执行命令,保证各项配置设置的精确无误是顺利完成安装的关键。通过上述的步骤分析和解决方案,非root用户安装MySQL时遇到"unknown variable 'defaults-file=**/my.cnf'"的问题应该可以得到妥善的解决。
1150 0

热门文章

最新文章

推荐镜像

更多