#mysql -u root -p //直接回车进入数据库,无需输入密码
mysql> use mysql;
Database changed
mysql> update user set authentication_string=password("123456") where User="root";
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
Bye
[root@zhangyx ~]# systemctl restart mysqld[root@zhangyx ~]# vim /etc/my.cnf[root@zhangyx ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 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.
4.恢复主配置文件,重启mysqld
#systemctl restart mysqld
5.再进入 vim /etc/my.cnf,然后把skip-grant-tables注释掉,最后再重启mysqld就可以了