[root@master ~]# vim /etc/my.cnf
[mysqld]
...
...
skip-host-cache
skip-name-resolve
skip-grant-tables
2.重启mysqld服务,并输入mysql直接进入数据库修改密码
[root@master ~]# systemctl restart mysql
[root@master ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18-log MySQL Community Server (GPL)
#修改密码
mysql> update mysql.user set authentication_string=password('123456') where user='root';
#刷新权限
mysql> flush privileges;
mysql> quit
3.删除三条参数,重启mysql搞定
[root@master ~]# vim /etc/my.cnf
[root@master ~]# systemctl restart mysql
[root@master ~]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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.
mysql>