Home > Database > Mysql Tutorial > body text

Mysql数据库权限丢失的解决办法

WBOY
Release: 2016-06-07 15:13:40
Original
1266 people have browsed it

欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入 今天要安装一个软件,需要用到Mysql数据库,要在里面建一个数据库,及相应的用户,我按其脚本执行建库脚本,很顺利,数据库成功建好,但在执行用户授权时却犯了一个低级错误: create database cact

欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入

    今天要安装一个软件,需要用到Mysql数据库,要在里面建一个数据库,及相应的用户,我按其脚本执行建库脚本,很顺利,数据库成功建好,但在执行用户授权时却犯了一个低级错误:

    create database cactidb ;

    grant all on cactidb.* to root@localhost;

    grant all on cactidb.* to cactiuser;

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

    1、 关闭mysql服务:service mysqld stop

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

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

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

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

    6、 重新启动mysql进程: service mysqld start

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

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

    update db set Select_priv='Y' where user='root';

    update db set Insert_priv='Y' where user='root';

    update db set Update_priv='Y' where user='root';

    update db set Delete_priv='Y' where user='root';

    update db set Create_priv='Y' where user='root';

    update db set Drop_priv='Y' where user='root';

    update db set References_priv='Y' where user='root';

    update db set Grant_priv='Y' where user='root';

    update db set Index_priv='Y' where user='root';

    update db set Alter_priv='Y' where user='root';

    update db set Create_tmp_table_priv='Y' where user='root';

    update db set Lock_tables_priv='Y' where user='root';

    update db set Create_view_priv='Y' where user='root';

    update db set Grant_priv='Y' where user='root';

    update db set Show_view_priv='Y' where user='root';

    update db set Create_routine_priv='Y' where user='root';

    update db set Alter_routine_priv='Y' where user='root';

    update db set Execute_priv='Y' where user='root';

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

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

Mysql数据库权限丢失的解决办法

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!