Setzen Sie das MySQL-Root-Passwort unter Linux zurück: Eine Schritt-für-Schritt-Anleitung.
Losing or forgetting the MySQL root password can be a daunting situation for database administrators. Jedoch, auf einem Linux -System, there are methods to reset the MySQL root password and regain access to your database. In diesem Artikel, we will guide you through the process of resetting the MySQL root password on Linux by modifying the MySQL configuration file (my.cnf), Gewährleistung der Sicherheit und Integrität Ihrer wertvollen Daten.
1. The first step in resetting the MySQL root password is to stop the MySQL service to prevent any active connections. Öffnen Sie ein Terminal auf Ihrem Linux -System und führen Sie den folgenden Befehl aus:
sudo systemctl stop mysql
2. Nächste, you need to modify the MySQL configuration file (my.cnf) den Authentifizierungsprozess vorübergehend zu deaktivieren. Öffnen Sie die Datei mit einem Texteditor:
sudo nano /etc/mysql/my.cnf
Suchen Sie die [mysqld]
Abschnitt in der Datei und fügen Sie die folgende Zeile darunter hinzu:
skip-grant-tables
NOTIZ: Falls, Wann [mysqld]
Nicht existieren, verwenden Sie diesen Code:
[mysqld]
skip-grant-tables
Speichern Sie die Änderungen und verlassen Sie den Texteditor.
3. Nach dem Ändern der Konfigurationsdatei, you need to restart the MySQL service for the changes to take effect. Führen Sie den folgenden Befehl im Terminal aus:
sudo systemctl restart mysql
NOTIZ: The MySQL service will now start without checking the user privileges, allowing you to reset the root password without providing the current password.
4. Now that MySQL is running with the authentication process disabled, open a terminal and connect to the MySQL server using the following command:
mysql -u root
Once connected to the MySQL server, execute the following SQL statement to flush privileges:
FLUSH PRIVILEGES;
NOTIZ: Ohne es, Sie erhalten Fehler bei allen Benutzeroperationen.
Once connected to the MySQL server, execute the following SQL statement to update the root password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Ersetzen Sie ‘new_password’ with your desired password. Nach dem Ausführen der Abfrage, you can exit the MySQL prompt by typing exit
oder quit
.
FLUSH PRIVILEGES;
exit;
NOTIZ: Vergessen Sie nicht, Code auf my.cnf zu kommentieren
#[mysqld]
#skip-grant-tables