新安装mysql5.7如果忘记登录密码,可以这样修改
1、先在my.ini文件中,mysqld下方,加入skip-grant-tables
2、跳过密码校验,重启mysql服务,再次进入mysql/bin命令行,
3、输入mysql -u root -p;直接进入mysql>
4、
我们把root@localhost用户删了,然后有新建了这个用户
mysql> delete from mysql.user where user='root' and host='localhost';
Query OK, 1 row affected (0.01 sec)
mysql> select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| mysql.sys | localhost |
+-----------+-----------+
1 row in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| mysql.sys | localhost |
| root | localhost |
+-----------+-----------+
2 rows in set (0.01 sec)
之后-->
mysql> grant all on *.* to 'root'@'localhost' identified by '123456' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
退出mysql,将skip-grant-tables注掉,然后重启mysql。此时在登陆就可以了。
参考:http://beibing.blog.51cto.com/10693373/1726799