mysql8没有了password函数,所以,使用传统的password()函数修改root密码的话,就会提示sql错误

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '("123456") where user='root'' at line 1

正确设置密码的方法是:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

此时提示修改成功,然后exit推出mysql。
然后
service mysql restart
重启
再次登陆即需要输入刚刚设置的密码就OK了