欢迎进入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命令的,所以只有我们手工来理发权限表