Monday, March 31, 2014

Reset MySQL Root User Password

Go to start of metadata
If you don't remember the Mysql root user's password, you can use this tip:
root@server:~# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
1) Debian has an user for manteinance jobs on mysql, and the credentials are saved on a file:
root@server:~# cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
host = localhost
user = debian-sys-maint
password = xxxxxxxxxxxxxxxx
socket = /var/run/mysqld/mysqld.sock
host = localhost
user = debian-sys-maint
password = p2DsK1FdSRgfrafjT
socket = /var/run/mysqld/mysqld.sock
basedir = /usr
2) Now access mysql with debian's user&pass and change the password for root user:
root@server#>mysql -u debian-sys-maint -p
mysql> use mysql;
mysql> UPDATE user SET password=PASSWORD('new_pass') WHERE user='root';
Query OK, 1 rows affected (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: 0
3) Then exit and reload Mysql
mysql> exit
root@server:~# service mysql reload
root@server:~# mysql -u root -pnew_pass
Welcome to the MySQL monitor. Commands end with or \g.
Your MySQL connection id is 8325
Server version: 5.1.63-0+squeeze1 (Debian)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

No comments:

Post a Comment