mysql误删root用户恢复方法

所属分类: 数据库 / Mysql 阅读数: 1275
收藏 0 赞 0 分享

装完数据库清理一些默认账号的时候不小心把root删除了,flush privileges 之后的新 root 忘了grant任何权限,查看mysqld选项里面有个 −−skip-grant-tables

复制代码 代码如下:

#/usr/libexec/mysqld --verbos --help

mysql5.5手册说明如下

复制代码 代码如下:

--skip-grant-tables

This option causes the server to start without using the privilege system at all, which gives anyone with access to the server unrestricted access to all databases. You can cause a running server to start using the grant tables again by executing mysqladmin flush-privileges or mysqladmin reload command from a system shell, or by issuing a MySQL FLUSH PRIVILEGES statement after connecting to the server. This option also suppresses loading of plugins, user-defined functions (UDFs), and scheduled events. To cause plugins to be loaded anyway, use the --plugin-load option.

--skip-grant-tables is unavailable if MySQL was configured with the --disable-grant-options option. See Section 2.10.2, “Typical configure Options”.

mysqld_safe是Unix/Linux系统下的MySQL服务器的一个启动脚本。这个脚本增加了一些安全特性,会在启动MySQL服务器以后继续监控其运行情况,并在出现错误的时候重新启动服务器。后台启动mysql

复制代码 代码如下:

#mysqld_safe --skip-grant-tables &

如果没有root账户就添加一个

复制代码 代码如下:

INSERT INTO user SET User='root',Host='localhost',ssl_cipher='',x509_issuer='',x509_subject='';

直接输入mysql连接并添加权限,这时候是不能使用grant命令的,只能用update

复制代码 代码如下:

UPDATE user SET Select_priv='Y',Insert_priv='Y',Update_priv='Y',Delete_priv='Y',Create_priv='Y',Drop_priv='Y',Reload_priv='Y',Shutdown_priv='Y',Process_priv='Y',File_priv='Y',Grant_priv='Y',References_priv='Y',Index_priv='Y',Alter_priv='Y',Show_db_priv='Y',Super_priv='Y',Create_tmp_table_priv='Y',Lock_tables_priv='Y',Execute_priv='Y',Repl_slave_priv='Y',Repl_client_priv='Y',Create_view_priv='Y',Show_view_priv='Y',Create_routine_priv='Y',Alter_routine_priv='Y', Create_user_priv='Y',Event_priv='Y',Trigger_priv='Y',Create_tablespace_priv='Y',authentication_string='' WHERE User='root';

注意我用的是mysql是5.5版本,可能操作过程中sql语句或其他地方有不同,语句执行完毕之后需要flush privileges ,还可能要重新登录才行。

更多精彩内容其他人还在看

MySQL查询和修改auto_increment的方法

这篇文章主要介绍了MySQL查询和修改auto_increment的方法,实例分析了select查询auto_increment及ALTER修改auto_increment的技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

mysql的左右内连接用法实例

这篇文章主要介绍了mysql的左右内连接用法,以一个完整实例较为详细的分析了mysql的左右内连接使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

mysql 查询重复的数据的SQL优化方案

这篇文章主要介绍了mysql 查询重复的数据的SQL优化方案,非常不错的方案推荐给大家。
收藏 0 赞 0 分享

MySQL左联多表查询where条件写法示例

这篇文章主要介绍了MySQL左联多表查询where条件写法示例,本文直接给出写法示例,需要的朋友可以参考下
收藏 0 赞 0 分享

Mysql修改datadir导致无法启动问题解决方法

这篇文章主要介绍了Mysql修改datadir导致无法启动问题解决方法,本文原因是SELINUX导致,用关闭SELINUX的方法解决了这个问题,需要的朋友可以参考下
收藏 0 赞 0 分享

Centos中彻底删除Mysql(rpm、yum安装的情况)

这篇文章主要介绍了Centos中彻底删除Mysql(rpm、yum安装的情况),本文直接给出操作代码,需要的朋友可以参考下
收藏 0 赞 0 分享

mysql误删root用户恢复方法

这篇文章主要介绍了mysql误删root用户恢复方法,本文操作是在mysql5.5版本下完成,其它版本仅作参考,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL编程中的6个实用技巧

这篇文章主要介绍了MySQL编程中的6个实用技巧,本文讲解了每一行命令都是用分号(;)作为结束、采用关联数组存取查询结果、TEXT、DATE、和SET数据类型等内容,需要的朋友可以参考下
收藏 0 赞 0 分享

mysql生成随机字符串函数分享

这篇文章主要介绍了mysql生成随机字符串函数分享,本文直接给出实现代码,需要的朋友可以参考下
收藏 0 赞 0 分享

Mysql大小写敏感的问题

这篇文章主要介绍了Mysql大小写敏感的问题的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多