Created
December 8, 2016 15:27
-
-
Save skorotkiewicz/e7e802c01e0c3a8b0abd10400b787294 to your computer and use it in GitHub Desktop.
Restore mysql root password on Debian/Ubuntu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
[client] | |
host = localhost | |
user = debian-sys-maint | |
password = xxxxxxxxxxxxxxxx | |
socket = /var/run/mysqld/mysqld.sock | |
[mysql_upgrade] | |
host = localhost | |
user = debian-sys-maint | |
password = xxxxxxxxxxxxxxxx | |
socket = /var/run/mysqld/mysqld.sock | |
basedir = /usr | |
root@server:~# | |
2) Now access mysql with debian's user&pass and change the password for root user: | |
#>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 | |
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 | |
owners. | |
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. | |
mysql> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment