0

I installed both MySQL and PhpMyAdmin via Homebrew. I get the following error when I try to login with root and its password:

Cannot log in to the MySQL server

I can log in to MySQL via the terminal with:

mysql -u root -p

PhpMyAdmin config:

/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'pass';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;

I'm running this on apache. I tried all the solutions on stackoverflow but they don't seem to work. Can anyone help me?

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Alexander
  • 396
  • 1
  • 9
  • 19

2 Answers2

5

The error "Cannot Log in to MySQL server" can have multiple causes. It simply means, that phpMyAdmin is not able to connect to the MySQL Server in general.

I had this issue too - in my case I've freshly installed MySQL. During the installation process a new root password is generated. But the MySQL Server forces you to set a new password for the root user, before that you can't execute any query. Sadly phpMyAdmin does not reflect the exact cause properly and just reports a failed connection 'Cannot log in to the MySQL server'.

I fixed it by

  1. logging into my mysql server with my cli:

    mysql -u root -p

  2. update root password:

    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('YOUR NEW PASSWORD HERE');

tmuecksch
  • 6,222
  • 6
  • 40
  • 61
  • Thanks for that! I have used mysql Workbench to reset the password. The issue was the password has expired but phpMyAdmin gives no message about it. – Fred May 07 '17 at 14:13
2

You can use both localhost or 127.0.0.1 as host declaration.

In your case you can try to use localhost and it will work.

Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
  • 2
    To clarify a bit, both are valid host declarations but they are handled differently by MySQL. `localhost` is a socket connection; `127.0.0.1` is TCP/IP networking. If the port is blocked or if MySQL is not listening for TCP/IP connections, then `localhost` must be used. Additionally, the permissions are different within MySQL -- the wildcard host indicator `%` does not match `localhost` connections. – Isaac Bennetch Oct 07 '15 at 15:41