Skip to content

Instantly share code, notes, and snippets.

@zh4n7wm
Created January 11, 2022 05:47
Show Gist options
  • Save zh4n7wm/a1b94d709c9dc79cdc0bd638a1ef1116 to your computer and use it in GitHub Desktop.
Save zh4n7wm/a1b94d709c9dc79cdc0bd638a1ef1116 to your computer and use it in GitHub Desktop.
mysql tips

MySQL tips

reset password

跳过权限检查,让 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment