MySQL5.7杂项(学习)
误删root账户
1、停止mysql服务
net stop myqsl
2、在mysql根目录下的my.ini中添加字段
skip-grant-tables
3、启动mysql服务
net start mysql
4、免密登录后添加root用户
insert into user set user='root',ssl_cipher='',x509_issuer='',x509_subject='';
5、赋予权限
update user set Host='localhost',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';
6、修改密码
update user set authentication_string=password('123456') where user='root';
7、重启并登录mysql测试其是否添加成功
报错
1、ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
因为添加了skip-grant-tables
语句,所以无法进行修改操作。
解决方法:执行flush privileges;
语句,再进行修改操作。
查看MySQL安装路径
- 登录MySQL
- 输入命令:
show variables like "%char%";
刪除mysql服务
- 进入CMD
sc delete mysql