MySQL数据库用户权限表丢失的解决方案

数据库 MySQL
本文主要介绍了MySQL数据库用户权限丢失的修复方法,接下来就让我们来一起学习一下吧。

在安装软件时,需要用到Mysql数据库,要在里面建一个数据库,及相应的用户,执行建库脚本,很顺利,数据库成功建好,但在执行用户授权时错误就产生了:

  1. createdatabasecactidb;  
  2.  
  3. grantalloncactidb.*toroot@localhost;  
  4.  
  5. grantalloncactidb.*tocactiuser; 

本来这是没什么的,但我之前已经把root@localhost这个用户给删除了,我只留下了用户名为root,host是%的用户,而我平常的操作为了方便都只是用root在本机登录的,我的mysql也只监听127.0.0.1这个地址,结果一执行grantalloncactidb.*toroot@localhost;这个命令立即完蛋了,我在本机用root登录就只能是root@localhost这个用户的权限,而不是一平常用的root@%这个用户,但root@localhost基本就是没有权限,按照Mysql的授权机制,我只有在其它主机登录才可使用root@%这个用户,而我根本就不可能从其它地址登录,这下把我给急坏了。由于严格的防火墙策略,我是不可能开放mysql的端口的。后来在网上找了相关资料,用以下方法解决了这个问题:

1、关闭mysql服务:servicemysqldstop。

2、./mysqld_safe--skip-grant-tables重新启动mysql。

3、重新使用root登录,此时不需要密码。

4、登录后删除root@local这个用户。

5、用ps查到mysqld进程,并用kill中止mysql进程。

6、重新启动mysql进程:servicemysqldstart。

7、当然使用这个方法也可重置root密码:setpasswordforroot=password(yourpass');

8、或者也可以重置root用户权限。

  1. updatedbsetSelect_priv='Y'whereuser='root';  
  2.  
  3. updatedbsetInsert_priv='Y'whereuser='root';  
  4.  
  5. updatedbsetUpdate_priv='Y'whereuser='root';  
  6.  
  7. updatedbsetDelete_priv='Y'whereuser='root';  
  8.  
  9. updatedbsetCreate_priv='Y'whereuser='root';  
  10.  
  11. updatedbsetDrop_priv='Y'whereuser='root';  
  12.  
  13. updatedbsetReferences_priv='Y'whereuser='root';  
  14.  
  15. updatedbsetGrant_priv='Y'whereuser='root';  
  16.  
  17. updatedbsetIndex_priv='Y'whereuser='root';  
  18.  
  19. updatedbsetAlter_priv='Y'whereuser='root';  
  20.  
  21. updatedbsetCreate_tmp_table_priv='Y'whereuser='root';  
  22.  
  23. updatedbsetLock_tables_priv='Y'whereuser='root';  
  24.  
  25. updatedbsetCreate_view_priv='Y'whereuser='root';  
  26.  
  27. updatedbsetGrant_priv='Y'whereuser='root';  
  28.  
  29. updatedbsetShow_view_priv='Y'whereuser='root';  
  30.  
  31. updatedbsetCreate_routine_priv='Y'whereuser='root';  
  32.  
  33. updatedbsetAlter_routine_priv='Y'whereuser='root';  
  34.  
  35. updatedbsetExecute_priv='Y'whereuser='root'; 

再把mysql.user表里root用户的所有字段都置为'Y'。

注意:使用--skip-grant-tables启动mysql时不可使用grant命令的,所以只有我们手工来设置权限表了。

关于MySQL权限表的问题就介绍到这里,如果大家想了解更多关于MySQL数据库的知识,不妨到这里看一下:http://database.51cto.com/mysql/,一定会让您满意的哦!

【编辑推荐】

  1. 利用mysql的audit审计功能记录用户操作信息
  2. MySQL索引背后的数据结构及算法之索引实现
  3. Facebook对MySQL依赖的后果将是“比死还糟
  4. 详解Discuz_WIN7_Apache_MySQL_PHP平台搭建
  5. MySQL错误:Can'tconnecttoMySQLserver(10060)
责任编辑:赵鹏 来源: 中国IT实验室
相关推荐

2011-03-07 16:42:05

MySQL数据库安全

2010-05-27 18:24:09

MySQL数据库密码

2011-03-28 13:11:18

MySQL数据库安全

2010-05-28 11:22:07

2009-11-18 16:10:00

2010-06-04 19:06:47

连接MySQL数据库

2018-03-26 12:58:52

数据库OracleMySQL

2011-03-03 18:09:14

2017-12-27 13:07:52

数据库MySQL主从复制

2011-03-24 15:41:42

数据库

2011-01-21 09:43:10

安恒数据库安全安全审计

2011-08-03 14:02:02

数据库连接ACCESS

2023-09-21 23:08:36

MySQL数据库死锁

2010-05-13 10:27:24

MySQL数据库

2010-03-03 15:16:17

2009-03-31 11:57:52

2011-07-12 16:42:41

2010-09-15 09:50:55

2024-02-06 07:56:20

数据库分布式数据库架构产品

2011-01-21 10:10:27

点赞
收藏

51CTO技术栈公众号