作了一些privilege相關的操做,root用戶忽然找不到系統的數據庫了,失去了root用戶的權限,找了很久才解決:mysql
關閉數據庫sql
sudo /etc/init.d/mysql stop數據庫
啓動安全模式數據庫安全
mysqld_safe --skip-grant-tables &ide
登陸數據庫,此時已經是root用戶,查看root用戶spa
mysqlrest
> use mysql;code
> select user,host from user;ip
修改root用戶權限ci
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';