MySQL – reset the root password
If you have forgotten the root password or another user database is a very simple way to reset it. All commands made from the root of the operating system.
For starters turn off the MySQL server:
1 | /etc/init.d/mysql stop |
Run in the background database server command:
1 | mysqld_safe --skip-grant-tables --skip-networking & |
We log on as root to the mysql database without a password:
1 | mysql -uroot mysql |
Then, in a mysql console:
1 2 3 | mysql> update user set Password=PASSWORD('nasze_nowe_hasło') WHERE User='root'; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0 |
1 2 | mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) |
1 2 | mysql> quit; Bye |
We resume the process from the background fg command, and when prompted:
1 | mysqld_safe --skip-grant-tables --skip-networking |
we use the CTRL + C, should appear:
1 | ^C130504 21:32:04 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended |
Run in normal mode, the MySQL server:
1 | /etc/init.d/mysql start |
Finally, you can check the password reset:
1 | mysql -uroot -p |