Zurücksetzen MySQL Root Passwort on Linux: Eine Schritt-für-Schritt-Anleitung.
Losing or forgetting the MySQL root Passwort can be a daunting situation for database administrators. Jedoch, on a Linux system, there are methods to reset the MySQL root Passwort and regain access to your database. In diesem Artikel, we will guide you through the process of resetting the MySQL root Passwort on Linux by modifying the MySQL configuration file (my.cnf), ensuring the security and integrity of your valuable data.
1. The first step in resetting the MySQL root Passwort is to stop the MySQL service to prevent any active connections. Open a terminal on your Linux system and execute the following command:
sudo systemctl stop mysql
2. Nächste, you need to modify the MySQL configuration file (my.cnf) to disable the authentication process temporarily. Open the file using a text editor:
sudo nano /etc/mysql/my.cnf
Suchen Sie die [mysqld]
section in the file and add the following line below it:
skip-grant-tables
NOTIZ: In case, when [mysqld]
not exist use this code:
[mysqld]
skip-grant-tables
Speichern Sie die Änderungen und verlassen Sie den Texteditor.
3. After modifying the configuration file, you need to restart the MySQL service for the changes to take effect. Execute the following command in the terminal:
sudo systemctl restart mysql
NOTIZ: Der MySQL service will now start without checking the user privileges, allowing you to reset the root Passwort without providing the current Passwort.
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: Without it, you will get errors on any user operations.
Once connected to the MySQL Server, execute the following SQL statement to update the root Passwort:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Replace ‘new_password’ with your desired Passwort. After running the query, you can exit the MySQL prompt by typing exit
oder quit
.
FLUSH PRIVILEGES;
exit;
NOTIZ: Don’t forget to comment code on my.cnf
#[mysqld]
#skip-grant-tables