Reimpostare la password di root su Mysql/MariaDB in ambiente Linux
In questo breve tutorial andremo a reimpostare la password di root su Mysql/MariaDB su Linux.
Consideriamo ad esempio di avere una macchina preinstallata di Centos 7 (per l’installazione seguire questo articolo), e consideriamo di avere già installato il database MariaDB.
Nel caso dovessimo ricevere il seguente errore
mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
nel caso ci fossimo dimenticati della password bisogna eseguire i seguenti passi
systemctl stop mariadb
mysqld_safe --skip-grant-tables --skip-networking &
mysql -u root -p
quando viene richiesta la password non inserire nulla e fare invio, ci restituirÃ
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.56-MariaDB MariaDB ServerCopyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]> use mysql;
MariaDB [mysql]> UPDATE user SET password=PASSWORD("nuova_password") WHERE User='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3 Changed: 0 Warnings: 0
MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> exit;
Adesso potremo entrare con la nuova password
systemctl restart mariadb
mysql -u root -p