sábado, 25 de diciembre de 2010

[kr12] Recuperar password de root en MySQL

En caso que se haya olvidado el password de MySQL o sea necesario averiguarlo por uno u otro motivo, se presentan unos sencillos pasos en este post para establecer uno nuevo. El proceso será realizado con comandos CentOS pero no varía mucho si se quiere realizar en otra distribución.

Detener el servicio MySQL
# service stop mysqld

Iniciar el servicio con unos parámetros especiales para que no solicite password
# mysqld_safe --skip-grant-tables --skip-networking --user=mysql &
[1] 29800
# Starting mysqld daemon with databases from /var/lib/mysql

Verificar que se haya iniciado el proceso con las opciones establecidas
# ps aux | grep mysql
root 29800 0.0 0.0 4484 1112 pts/0 S 18:30 0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables --skip-networking --user=mysql
mysql 29852 0.0 0.4 136268 17420 pts/0 Sl 18:30 0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock --skip-grant-tables --skip-networking
root 29889 0.0 0.0 3940 732 pts/0 S+ 18:30 0:00 grep mysql

Ingresar al mysql sin password
# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Se cambia el password para el usuario root y se sale del mysql
mysql> update user set password=password('0p3nMySQLGr0up') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit

Se comprueba el acceso con el nuevo password
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

No hay comentarios: