Mysql forgotten password

windows platform

  1. Stop the MySQL service

  2. 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';
    
  3. 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"
    
  4. After the carriage return, you can ctrl+c to stop

  5. Start the MySQL service and log in with the new password.

mac receipt

  1. stop mysql service

  2. 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

  3. Add a line at the end of the file

    skip-grant-tables
    
  4. 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';
    
  5. stop the service

  6. In my.cnf, delete the line skip permission check just added

  7. Start the MySQL service

Guess you like

Origin blog.csdn.net/longz_org_cn/article/details/131931522