最近发然发现有一个MySQL实例的root@'localhost'用户没有了给新建用户赋权的权限了,还纳闷了一阵。
对于这个问题,其处理方式其实与忘记root@'localhost'通行口令的方式一样,都是通过mysql的skip-grant-tables实现。
1、关闭原实例,具体可以在登录到命令行中通过
shutdown;
关闭当前实例
2、临时以跳过验证模式启动数据库
$PATH/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --console --skip-grant-tables
3、不使用--password验证登录数据库
$PATH/mysql -uroot -P3306
4、进入mysql数据库并赋权限
use mysql;
select user,host,plugin,Grant_priv,Super_priv from user;
update user set Grant_priv='Y',Super_priv='Y' where user='root' and host='localhost';
flush privileges;
exit;
5、验证
mysql -uroot -p
grant select on test.* to user_test;
6、重新以正常方式启动MySQL实例
mysql -uroot -p -e"shutdown;"
nohup $PATH/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &