Mysql loses its root password

Solution 1:

This answer is in connection with Ruby on Rails framework where this behavior occurred

  1. have mysql with user root and password
  2. bootstrap new rails project using with mysql "rails new projectname
    -d mysql"
  3. do not modify config/database.yml - defaults credentials for server are name: root, password is blank
  4. rake db:create prompt show up - asking for root password and then when you provide root password

the answer is in GRANT command on line 68 in here

basically it executed GRANT command with credentials matches your current database.yml

Solution 2:

1) If you can, enable SQL logging.

log = /var/log/mysql/mysql.log

That will allow you to trace when the password gets updated and from there, you can correlate with some other activity with other logs.

2) Do you have an admin process running (e.g. Plesk) or something similar? You may want to check to see if that is not resetting the logins by default.

3) Are you the only one who have access to the server? If not, you may want to verify that nobody else have access to the database or at least not have the root password to the SQL database.