Mysql8密码忘记,解决办法
①sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
添加:
②重启服务
sudo /etc/init.d/mysql restart
③进入mysql
mysql -uroot -p
随意输入密码进入
下面你可能遇见这些错误:
采用这条语句update mysql.user set authentication_string=password('123456') where user='root';
错误信息:
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 BY '123456';
出错:
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
查阅资料需要先进行:flush privileges;
接着你再使用语句:ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
出现密码太简单的错误:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password.policy=0;
密码太简单错误解决方法:
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)
修改密码等级以及密码长度要求。
然后
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
还在报错:
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
最后改用这条语句:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'
再次进行:
flush privileges;
ctrl+d退出
最后注释掉这句话
重启服务,并进入mysql