简体   繁体   中英

How to recover MySQL password?

I installed MySQL earlier in the week and forgot the root password.

I assumed that uninstalling and re-installing MySQL would allow me to create a new root password. However, now during the re-installation process it's asking for me to provide the previous password that I don't have anymore.

Every suggestion that I've found to fix this issue states that I need to find MySQL within 'Services' of Windows but MySQL is not in there or the Task Manager.

I always use this solution to reset the password;)

  • Stop MySQL

     sudo service mysql stop
  • Make MySQL service directory.

     sudo mkdir /var/run/mysqld
  • Give MySQL user permission to write to the service directory.

     sudo chown mysql: /var/run/mysqld
  • Start MySQL manually, without permission checks or networking.

     sudo mysqld_safe --skip-grant-tables --skip-networking &
  • Log in without a password.

     mysql -uroot mysql
  • Update the password for the root user.

     UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%'; EXIT;
  • Turn off MySQL.

     sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
  • Start the MySQL service normally.

     sudo service mysql start

Edit:

This is a documentation for the Windows.

https://dev.mysql.com/doc/mysql-windows-excerpt/5.7/en/resetting-permissions-windows.html

Did you start the Mysql?

https://superuser.com/questions/666521/how-do-i-start-a-mysql-server-on-windows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM