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