windows platform
-
Stop the MySQL service
-
In any path, create a new text file and add the operation of changing the password
# 例如: # 在桌面上创建一个文件 root_password.txt # 其中的内容如下 alter user root@localhost identified by '12345678';
-
Run Command Prompt as administrator
mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --init-file="C:\Users\shawn\Desktop\root_password.txt"
-
After the carriage return, you can ctrl+c to stop
-
Start the MySQL service and log in with the new password.
mac receipt
-
stop mysql service
-
Open the my.cnf file
File location:
dmg direct loading -> /etc/my.cnf
homebrew ->
intel -> /usr/local/homebrew/etc/my.cnf
M1 -> /opt/homebrew/etc/my.cnf
-
Add a line at the end of the file
skip-grant-tables
-
Log in to MySQL without a password and change the password
# 登录到MySQL mysql -uroot -p # 如果提示输入密码,直接回车即可 # 刷新权限 flush privileges; # 修改密码,密码要求同时包含大写字母、小写字母、数字,长度至少8位。 # 如果想要修改为简单的密码,看下一段 alter user 'root'@'localhost' identified by 'NewPassword123';
-
stop the service
-
In my.cnf, delete the line skip permission check just added
-
Start the MySQL service