mysql忘记root密码解决办法:

mysql 5.7以上版本,该密码的变量为authentication_string=password('xxxxx')

>update user set authentication_string=password('123456') where user='root';

另外alter user改密码的命令为:

> alter user root@'localhost' identified by ‘xxxxx’;

SET PASSWORD命令为:

> SET PASSWORD for root@'localhost'=password('xxxxxx');

# vi /etc/mysql/my.cnf  (在[mysqld]下添加)
按a或i进入编译模式
skip-grant-tables
按Esc键退出编译模式
:wq (保存并退出)
# service mysql restart
# mysql
> show databases;
>use mysql;
>update user set password=password('123456') where user='root';  (将root密码改为123456)
>flush privileges;
>quit
# vi /etc/mysql/my.cnf  (在[mysqld]下,将添加的再注释掉)
按a或i进入编译模式
#skip-grant-tables
按Esc键退出编译模式
:wq (保存并退出)
# service mysql restart
# mysql -u root -p123456