Child pages
  • change mysql password
Skip to end of metadata
Go to start of metadata

Change Password

First, you need to SSH into the host from which you will be connecting to mysql.

Next, you want to make a backup copy of your ~/.mysql_history file (if it exists) so that you don't lose your command history in mysql:

cp ~/.mysql_history ~/.mysql_history_backup

Next, you'll want to start the mysql client:

mysql -h themysqlhost -u username -p

To change your password once inside the mysql client:

SET PASSWORD = PASSWORD('yournewpassword');
flush privileges;

The password inside the quotes is the new password. If you get an error when executing "flush privileges", ignore it.

Next, do the following to get rid of your mysql command history (as your password is stored in plain text there after you execute this command):

shred ~/.mysql_history
rm ~/.mysql_history

The shred command fills the file with nonsense so that it's harder (maybe impossible?) to recover the password from it.

After you've removed the mysql_history file, do the following to restore your backup (if it exists):

cp ~/.mysql_history_backup ~/.mysql_history
  • No labels