phpMyAdmin #1045 Cannot log in to the MySQL server

I was using phpMyAdmin and trying to login to my server with a new user that I’d created called ‘pma’ but I was getting the error “#1045 Cannot log in to the MySQL server”. The ‘pma’ user was also my phpMyAdmin control user and as its login wasn’t working advanced features of phpMyAdmin weren’t functional and I was getting an error letting me know.

I thought maybe the problem was that I’d specified the password for the ‘pma’ user incorrectly so I reset the ‘pma’ user password just to be user:

  update user set password=PASSWORD("secret") where user='pma';

But the problem persisted. I had a look in the mysql.user table to see what was in there. The results included the following:

  mysql> use mysql;
  Database changed
  mysql> select Host, User, Password from user;
  +-----------+-----------+-------------------------------------------+
  | Host      | User      | Password                                  |
  +-----------+-----------+-------------------------------------------+
  | localhost |           |                                           |
  | %         | pma       | *BD053A55278DA675E32F28360C759B3FBEE32B3E |
  +-----------+-----------+-------------------------------------------+

Note the entry on the first line with a blank username. I have no idea how that entry got into my mysql.user table but basically it seems to be interpreted as “any user” at localhost with no password. I didn’t like the look of that so I deleted that entry. After that entry had been deleted the login for my ‘pma’ user started to work.