步骤:
1、找到配置文件加入跳过密码输入进入 skip-grant-tables
2、更新用户表密码 update mysql.user set authentication_string=PASSWORD('输入你的密码') where User='root';
3、注释skip-grant-tables
4、重启mysql
具体:
a).输入:whereis my.cnf 找配置文件
[root@iZuf62p8v9cro017s56dbsZ ~]# whereis my.cnf
my: /etc/my.cnf
b)、编辑文件:
[root@iZuf62p8v9cro017s56dbsZ ~]# vi /etc/my.cnf
按下i键后,将skip-grant-tables粘贴到【mysql】下
按Esc键, 输入:wq! (保存退出)
c)、进入mysql
mysql -uroot -p
Enter password: (直接回车)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
d)、修改表
update mysql.user set authentication_string=PASSWORD('输入你的密码') where User='root';
update mysql.user set authentication_string=PASSWORD('12556') where User='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
e)、注释my.cnf文件 的skip-grant-tables
f)、重新输入 mysql -uroot -p ,然后输入你设置的密码