SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'

Solution 1:

It turns out you can't use the root user in 5.7 anymore without becoming a sudo'er. That means you can't just run mysql -u root anymore and have to do sudo mysql -u root instead.

That also means that it will no longer work if you're using the root user in a GUI (or supposedly any non-command line application). To make it work you'll have to create a new user with the required privileges and use that instead.

See this answer for more details.

Solution 2:

These steps worked for me on several systems using Ubuntu 16.04 (Xenial Xerus), Apache 2.4, MariaDB, and PDO:

  1. Log into MYSQL as root

     mysql -u root
    
  2. Grant privileges. For a new user, execute:

     CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
     GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
     FLUSH PRIVILEGES;
    

    UPDATE for Google Cloud Instances

    MySQL on Google Cloud seem to require an alternate command (mind the backticks).

     GRANT ALL PRIVILEGES ON `%`.* TO 'newuser'@'localhost';
    

    NOTE: Depending on wether your new user should be able to grant all privileges to other users as well you could extend the command by the GRANT WITH option. Please be aware that this exposes your user to be sudoer and hence become a higher security risk.

     GRANT ALL PRIVILEGES ON `%`.* TO 'newuser'@'localhost' GRANT WITH OPTION;
    
  3. Bind to all addresses:

    The easiest way is to comment out the line in your /etc/mysql/mariadb.conf.d/50-server.cnf or /etc/mysql/mysql.conf.d/mysqld.cnf file, depending on what system you are running:

      #bind-address = 127.0.0.1
    
  4. Exit MySQL and restart MySQL

      exit
      service mysql restart
    

By default it binds only to localhost, but if you comment the line it binds to all interfaces it finds. Commenting out the line is equivalent to bind-address=*.

To check the binding of the MySQL service, execute as root:

netstat -tupan | grep mysql

Solution 3:

Use:

sudo mysql -u root

And now in the MySQL client:

use mysql;
update user set plugin='' where User='root';
flush privileges;
\q

Now you should be able to log in as root in phpMyAdmin.

(It was found here.)