感谢:https://blog.csdn.net/ma15732625261/article/details/54629613
只针对5.7版本,其他版本没有试过,特别是新版本有可能不行。
正题:
1、cmd输入mysql -u root -p,然后输入密码(或者直接回车,新装的sql默认无密码)
2、进入mysql命令行后输入use mysql;
3、输入update mysql.user set authentication_string=password('此处设置自己的密码') where user='root' and Host = 'localhost';
4、输入flush privileges;
5、输入quit;
完成