Home Software Linux Obnovení „zapomenutého“ root hesla na os Debian 6

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> exit

Leave a Reply

Galerie