Redefinir a senha root do MySQL no Linux: Um guia passo a passo.
Losing or forgetting the MySQL root password can be a daunting situation for database administrators. No entanto, em um sistema Linux, there are methods to reset the MySQL root password and regain access to your database. Neste artigo, we will guide you through the process of resetting the MySQL root password on Linux by modifying the MySQL configuration file (meu.cnf), garantindo a segurança e integridade de seus dados valiosos.
1. The first step in resetting the MySQL root password is to stop the MySQL service to prevent any active connections. Abra um terminal em seu sistema Linux e execute o seguinte comando:
sudo systemctl stop mysql
2. Próximo, you need to modify the MySQL configuration file (meu.cnf) para desativar o processo de autenticação temporariamente. Abra o arquivo usando um editor de texto:
sudo nano /etc/mysql/my.cnf
Localize o [mysqld]
seção no arquivo e adicione a seguinte linha abaixo dela:
skip-grant-tables
OBSERVAÇÃO: Em caso, quando [mysqld]
não existe use este código:
[mysqld]
skip-grant-tables
Salve as alterações e saia do editor de texto.
3. Depois de modificar o arquivo de configuração, you need to restart the MySQL service for the changes to take effect. Execute o seguinte comando no terminal:
sudo systemctl restart mysql
OBSERVAÇÃO: 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;
OBSERVAÇÃO: Sem isso, você receberá erros em qualquer operação do usuário.
Once connected to the MySQL server, execute the following SQL statement to update the root password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Substitua ‘nova_senha’ with your desired password. Depois de executar a consulta, you can exit the MySQL prompt by typing exit
ou quit
.
FLUSH PRIVILEGES;
exit;
OBSERVAÇÃO: Não se esqueça de comentar o código em my.cnf
#[mysqld]
#skip-grant-tables