If you need to recover a forgotten MySQL or MariaDB password, if the password was entered at a shell prompt while starting either program with the
mysql
command and the
user's account uses the
Bash shell,
you may be able to find the password in the
Bash history file for the user's acount, which is .bash_history
in the user's home directory. E.g., if the user entered the command below:
$ mysql --user=users_acct --password=users_password
If you viewed the contents of the Bash history file for that user's account you would see the command with the password just as you would see other commands entered from the user's account. E.g., if the user's account was jdoe:
# grep mysql ~jdoe/.bash_history mysql --user=users_account --password=users_password
But, if the user entered the command mysql -u users_acct -p
and
didn't follow the `-p` or `--password` with the password, but, instead, just
entered one of those parameters without putting the password immediately
after it, that leads to the system prompting the user for the password and
the password won't be in the Bash history file.
Note: if the user is still logged in to the account for which you are
checking the .bash_history
file, you won't see the commands
entered during that login session until after the user logs out of the
session.
If you are logged into the relevant account or use the
su command, which is
also referred to as the "substitute user", "switch user", or "super user"
command, you can use the history
command to view the commands
entered at the command line. E.g., you could use history | grep
mysql
.