删除和恢复 MySQL 数据库 root 帐号
来源:靑龍一笑的博客 作者:靑龍一笑 发布时间:2017-01-09 10:45:36 点击量:702 评论:0
出于安全考虑,我们应该删除 MySQL 数据库的 root 帐号,在删除 root 帐号之前,使用 root 帐号登录到 MySQL 数据库,查找出所有 root 帐号:
mysql> select Host,User from mysql.user where User='root';
创建一个与 root 同等权限的本地帐号:
mysql> grant all privileges on *.* to 'sysdba'@'127.0.0.1' identified by 'sysDBApwd';
mysql> flush privileges;
mysql> flush privileges;
以新创建的 sysdba 帐号登录到 MySQL,删除所有 root 帐号:
[root@RicenOS ~]# mysql -h127.0.0.1 -usysdba -psysDBApwd
mysql> drop user root@'localhost';
mysql> drop user root;
mysql> select Host,User from mysql.user where User='root';
Empty set (0.00 sec)
mysql> drop user root@'localhost';
mysql> drop user root;
mysql> select Host,User from mysql.user where User='root';
Empty set (0.00 sec)
如果是误删除 root 帐号,想要恢复的话,可以进行如下操作:
mysql> insert into mysql.user set User='root',Host='localhost',ssl_cipher='',x509_issuer='',x509_subject='';
mysql> update mysql.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';
mysql> update mysql.user set authentication_string=password('db2017pwd') where User='root';
mysql> flush privileges;
mysql> update mysql.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';
mysql> update mysql.user set authentication_string=password('db2017pwd') where User='root';
mysql> flush privileges;
版权所有 © 2005-2023 靑龍一笑的博客 Powered by C.S.Ricen
Copyright © 2005-2023 by www.ricensoftwares.com.cn All Rights Reserved.
Copyright © 2005-2023 by www.ricensoftwares.com.cn All Rights Reserved.