跳过权限检查,让 root
没有密码就能进入 MySQL
sudo systemctl edit mysql
ExecStart=/usr/sbin/mysqld
后面添加 --skip-grant-tables --skip-networking
重启服务
sudo systemctl daemon-reload
sudo systemctl restart mysql
进入 MySQL
$ mysql -u root -p
We logged into the database server without loading grant tables (because we used --skip-grant-tables option). So we can't user ALTER USER command which his needed to reset password. To load grant tables, run the following command from MySQL shell prompt:
加载 grant table
mysql> FLUSH PRIVILEGES;
将密码设置为空
mysql> UPDATE mysql.user SET authentication_string=null WHERE user='root';
重置密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'your-password';
如果报 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> SET GLOBAL validate_password.length = 6;
mysql> set global validate_password.policy=0;