La password di root per il server MySQL è un dato da considerarsi estremamente sensibile, vista l’importanza che ricopre. Diventa di vitale importanza tenere sempre a portata di mano una procedura che ci permetta di recuperare questo dato in caso di necessità.
E’ possibile recuperare la password di root eseguendo questi 5 passi:
Step # 1: Fermare il processo server MySQL
Step # 2: “Startare” il processo server MySQL con l’opzione –skip-grant-tables
Step # 3: Connettersi al server MySQL come utente root
Step # 4: Configuriamo la nuova password per l’account di root
Step # 5: Usiamo e “restartiamo” il server MySQL.
Per ogni step, di seguito è possibile visionarne i commandi (da eseguire loggati come utente root):
Step # 1 : Fermare il server MySQL
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld.
Step # 2: Avviare il server MySQL senza password:
# mysqld_safe --skip-grant-tables &
Output:
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started
Step # 3: Connessione al server MySQL usando il client MySQL:
# mysql -u root
Output:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>
Step # 4: Settiamo la nuova password per l’utenza root del server MySQL
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Step # 5: Stoppiamo il server MySQL:
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended
[1]+ Done mysqld_safe –skip-grant-tables
Step # 6: Avviamo il server MySQL ed effettuiamo il primo accesso
# /etc/init.d/mysql start
# mysql -u root -p