1.vim /etc/my.cnf
2.在[mysqld]中添加
skip-grant-tables
例如:
[mysqld]
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
3.重启mysql
service mysql restart
4.用户无密码登录
mysql -uroot -p (直接点击回车,密码为空)
5.选择数据库
use mysql;
6、ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
提示ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
mysql> select user,host from user;
7、注意我的root,host是'%'
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123';
8、退出 service mysqld restart