MYSQL的root用户被删除后重建

删除root用户

drop user root@'localhost';

停止Mysql

service mysql stop

进入安全模式

mysqld_safe --skip-grant-tables --skip-networking &

添加用户并修改密码

INSERT INTO user SET User='root',Host='localhost',ssl_cipher='',x509_issuer='',x509_subject='';
update user set password=password("654321") where user="root";

insert into user(user,host,password,ssl_type,ssl_cipher,x509_issuer,x509_subject) values('root','localhost',PASSWORD('123'),'','','','');

授权root用户,否则无任何权限

update user set select_priv='y', insert_priv='y',update_priv='y',Alter_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',create_user_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' where user='root' and Host='localhost';

mysql重新启动

service mysql stop
service mysql start

忘记密码

5.6以前版本
update mysql.user set password=PASSWORD('123') where user='oldboy' and host='10.0.0.%';
flush privileges;

5.7版本
update mysql.user set authentication_string=PASSWORD('123') where user='oldboy' and host='10.0.0.%';

 

posted @ 2020-03-01 22:17  葫芦杯  阅读(1624)  评论(0编辑  收藏  举报