今天同事,调整mysql安全,在删除用户的时候误删了 root@localhost,后来加进去了,但是在登录发现数据库很多库都没有了,顿时懵逼,考虑恢复数据,稍后我看到了,想起当年也出现过类似情况,主要是因为root用户没有权限,所以跳过授权表,经过查询权限,真的缺少,所以将其都由N改为Y ,在次测试,OK,以下是处理步骤。
第一步,跳过授权表登录mysql1、pkill 停止 实例进程
2、mysqld_safe --defaults-file=/data/3306/my.cnf --skip-grant-tables &
3、mysql -S /data/3306/mysql.sock
4、UPDATE mysql.user SET password=PASSWORD('oldboy123') WHERE user='root' and host='localhost';
5、flush privileges;
6、kill掉mysqld_safe 进程
7、/etc/init.d/msyql start 正常启动
登录即可 mysql -uroot -poldboy123
第二步、修改权限(也可以初始化root密码)mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed