Retrieving the MySQL Root Password When Lost
If you've forgotten your MySQL root password, fret not. There are methods available to retrieve or reset it without knowing the original password.
Option 1: File-Based Retrieval
Traditionally, MySQL stores the root password in the ~/.mylogin.cnf file on Unix-based systems. However, you mentioned not having a directadmin directory locally, which may indicate that you're using a different system.
Option 2: Temporary Root Access
For Ubuntu users, you can temporarily gain root access to your MySQL database by following these steps:
Change the root password:
UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root'; FLUSH PRIVILEGES;
Quit safe mode and restart MySQL:
mysqladmin shutdown sudo service mysql start
Note: This method works for MySQL 5.7 and below. For versions 8.0 and above, the password field in the mysql.user table has been removed. Instead, use the authentication_string field.
The above is the detailed content of How do I retrieve my lost MySQL root password?. For more information, please follow other related articles on the PHP Chinese website!