Mysql – Cannot log in to the MySQL server (PhpMyAdmin)

MySQLphpmyadmin

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?

Best Answer

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');