MySQL重置root口令
在配置文件中修改 [mysqld] 的配置, 在下面增加skip-grant-tables
对应Ubuntu20.04, 路径是 /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
skip-grant-tables
然后重启 mysql , 就可以不需要口令直接登录
mysql -uroot
修改口令
# 先执行这个, 否则会报错 ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
# 再执行这个修改
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'newpassword';
Query OK, 0 rows affected (0.02 sec)