Mysql
 SQL >> Database >  >> RDS >> Mysql

MySQL: come reimpostare o cambiare la password di root

Ecco come impostare, cambiare o reimpostare la password di root di MySQL su Ubuntu Linux. Inserisci queste righe nel terminale.

  1. Ferma il server MySQL: sudo /etc/init.d/mysql stop
  2. Avvia la configurazione di mysqld: sudo mysqld --skip-grant-tables &

In alcuni casi devi prima creare la directory /var/run/mysqld:

sudo mkdir -v /var/run/mysqld && sudo chown mysql /var/run/mysqld
  1. Accedi a MySQL come root: mysql -u root mysql
  2. Sostituisci YOURNEWPASSWORD con la tua nuova password:

Per MySQL < 8.0

UPDATE mysql.user SET Password = PASSWORD('YOURNEWPASSWORD') WHERE User = 'root';
FLUSH PRIVILEGES;
exit;

Nota: su alcune versioni, se la colonna password non esiste, puoi provare:
UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';

Nota: questo metodo non è considerato il più sicuro per reimpostare la password, ma funziona.

Per MySQL >= 8.0

ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD';

Riferimenti:

  1. Set / Change / Reset the MySQL root password on Ubuntu Linux
  2. How to Reset the Root Password (v5.6)
  3. How to Reset the Root Password (v8.0)

Riavviando MySQL con --skip-grant-tables l'autenticazione è completamente disattivata: assicurati di riavviare il server in modalità normale subito dopo il cambio della password e di non lasciare il servizio esposto in quello stato.