解决误删Mysql中root所有权限的方法!

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介:

背景:

    长时间的对着电脑,造成了"神志不清",一不小心在Mysql下误操作了“revoke all on *.* from 'root'@'localhost'; ”,这个命令的意思就是删除mysql中最高权限的用户root的所有权限。因为本机mysql的密码为空,虽然依旧可以进去mysql,但再也不法执行修改操作。


解决方法:

1、首先杀掉mysql进程

#pkill mysql

2、以--skip-grant-tables方式启动

#/usr/local/mysql/bin/mysqld_safe  --user mysql --skip-grant-tables&

3、更新的MYSQL.USER表的所有字段中为N的为Y

# /usr/local/mysql/bin/mysql  进入mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
>use mysql;
update  user  set  Select_priv = 'Y'  where  user  'root' ;
update  user  set  Insert_priv = 'Y'  where  user  'root' ;
update  user  set  Update_priv = 'Y'  where  user  'root' ;
update  user  set  Delete_priv = 'Y'  where  user  'root' ;
update  user  set  Create_priv = 'Y'  where  user  'root' ;
update  user  set  Drop_priv = 'Y'  where  user  'root' ;
update  user  set  Reload_priv = 'Y'  where  user  'root' ;
update  user  set  Shutdown_priv = 'Y'  where  user  'root' ;
update  user  set  Process_priv = 'Y'  where  user  'root' ;
update  user  set  File_priv = 'Y'  where  user  'root' ;
update  user  set  Grant_priv = 'Y'  where  user  'root' ;
update  user  set  References_priv = 'Y'  where  user  'root' ;
update  user  set  Index_priv = 'Y'  where  user  'root' ;
update  user  set  Alter_priv = 'Y'  where  user  'root' ;
update  user  set  Show_db_priv = 'Y'  where  user  'root' ;
update  user  set  Super_priv = 'Y'  where  user  'root' ;
update  user  set  Create_tmp_table_priv = 'Y'  where  user  'root' ;
update  user  set  Lock_tables_priv = 'Y'  where  user  'root' ;
update  user  set  Execute_priv = 'Y'  where  user  'root' ;
update  user  set  Repl_slave_priv = 'Y'  where  user  'root' ;
update  user  set  Repl_client_priv = 'Y'  where  user  'root' ;
update  user  set  Create_view_priv = 'Y'  where  user  'root' ;
update  user  set  Show_view_priv = 'Y'  where  user  'root' ;
update  user  set  Create_routine_priv = 'Y'  where  user  'root' ;
update  user  set  Alter_routine_priv = 'Y'  where  user  'root' ;
update  user  set  Create_user_priv = 'Y'  where  user  'root' ;
update  user  set  Event_priv = 'Y'  where  user  'root' ;
update  user  set  Trigger_priv = 'Y'  where  user  'root' ;


总结:

    权限问题最后要保证“mysql.user”表中 host为“localhost”和“%”都有root的所有权限。 

    host列是指定登录的ip,比如说 user=root host=192.168.1.1 ,这里的意思就是说,root用户只能通过 192.168.1.1的客户端去访问,而%则是个通配符, 如果host=192.168.1.%,那么就表示 只要是 ip为host=192.168.1.前缀的客户端都可以连接,那么host=%的话则表示所有ip都有权去连接,这也就是为什么在开启远程连接的时候,大部分人都直接把host改成%的缘故,因为省事。


本文转自Jacken_yang 51CTO博客,原文链接:http://blog.51cto.com/linuxnote/1641488,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2月前
|
网络协议 关系型数据库 MySQL
mysql8.0远程连接权限设置
mysql8.0远程连接权限设置
70 0
|
28天前
|
关系型数据库 MySQL Linux
linux CentOS 7.4下 mysql5.7.20 密码改简单的方法
linux CentOS 7.4下 mysql5.7.20 密码改简单的方法
24 0
|
29天前
|
关系型数据库 MySQL 数据库
mysql添加用户并设置数据库权限
mysql添加用户并设置数据库权限
|
7天前
|
缓存 关系型数据库 MySQL
mysql用in查询大量数据的方法
在MySQL中使用 IN 子句来查询大量数据时,性能可能会成为一个问题
|
7天前
|
关系型数据库 MySQL PHP
【PHP 开发专栏】PHP 连接 MySQL 数据库的方法
【4月更文挑战第30天】本文介绍了 PHP 连接 MySQL 的两种主要方法:mysqli 和 PDO 扩展,包括连接、查询和处理结果的基本步骤。还讨论了连接参数设置、常见问题及解决方法,如连接失败、权限和字符集问题。此外,提到了高级技巧如使用连接池和缓存连接信息以优化性能。最后,通过实际案例分析了在用户登录系统和数据管理中的应用。
|
8天前
|
存储 关系型数据库 MySQL
linux安装MySQL8.0,密码修改权限配置等常规操作详解
linux安装MySQL8.0,密码修改权限配置等常规操作详解
|
11天前
|
安全 关系型数据库 MySQL
node实战——后端koa结合jwt连接mysql实现权限登录(node后端就业储备知识)
node实战——后端koa结合jwt连接mysql实现权限登录(node后端就业储备知识)
20 3
|
13天前
|
存储 SQL 关系型数据库
误删了MySQL注册表怎么办
【4月更文挑战第23天】
|
18天前
|
关系型数据库 MySQL 数据库
docker 安装mysql(踩坑踩得想哭 详细解决教程)ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using pa
docker 安装mysql(踩坑踩得想哭 详细解决教程)ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using pa
20 1
|
25天前
|
SQL 关系型数据库 MySQL
MySql创建用户并配置权限
MySql创建用户并配置权限
18 0