To recover MySQL password you simply need to
1) shutdown mysql database if it's possible or just kill with TERM
In Linux :
# service mysqld shutdown
For killing process
# kill -TERM `ps axxwww | grep mysqld`
2) Run database with "skip grants" option
# /bin/sh /usr/bin/mysqld_safe --defaults-file=/etc/my.cnf \
--pid-file=/var/run/mysqld/mysqld.pid --skip-grant-tables
3) Log in into database and change password
# mysqlmysql> use mysql; mysql> update user set password=PASSWORD("newpassword") where user="root"; mysql> quit;
4) Restart database and log in with new password
To recover Postgresql password
1) Edit postgresql config file pg_hba.conf and change line from :
local all postgres peer
to
local all postgres trust
2) Restart postgresql server :
# service postgresql restart
3) Log in into database and change password
# psql -U postgres
postgres=# use template1
postgres-# alter user postgres with password 'secret';postgres-# \q
4) Restart postgresql server