做了一些privilege相关的操作,root用户突然找不到系统的数据库了,失去了root用户的权限,找了好久才解决:
关闭数据库
sudo /etc/init.d/mysql stop
启动安全模式数据库
mysqld_safe --skip-grant-tables &
登录数据库,此时已是root用户,查看root用户
mysql
> use mysql;
> select user,host from user;
修改root用户权限
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‘ where user=‘root‘ and host=‘localhost‘;
最后重启数据库 /etc/init.d/mysql restart
如果碰到忘记root密码也可以采用上面的方式登录root账号,
update
user
set
authentication_string=
password
(
‘new password‘
)
where
user
=
‘root‘;
本文出自 “沉淀” 博客,请务必保留此出处http://jupiterbee.blog.51cto.com/3364619/1981109
原文地址:http://jupiterbee.blog.51cto.com/3364619/1981109