SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'
<p>I just installed <a href="https://en.wikipedia.org/wiki/Ubuntu_version_history#Ubuntu_16.04_LTS_.28Xenial_Xerus.29" rel="noreferrer">Ubuntu 16.04</a> (Xenial Xerus) and installed web server on it. Everything works well, but I cannot access database.
Even if I create new user and grant all privileges, I can't create database</p>
<p>In PHP I'm getting this error:</p>
<pre class="lang-none prettyprint-override"><code>SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'
</code></pre>
<p>When I try to login in terminal, it works, but in PHP and phpMyAdmin don't.</p>
<p>PHP Code:</p>
<pre><code>protected $host = '127.0.0.1';
protected $db = 'dbname';
protected $name = 'root';
protected $pass = 'root';
protected $conn;
private static $settings = array(
    PDO::MYSQL_ATTR_INIT_COMMAND =&gt; 'SET NAMES utf8'
);

public function __construct() {
    try {
        $this-&gt;conn = new PDO(&quot;mysql:host=$this-&gt;host;dbname=$this-&gt;db&quot;, $this-&gt;name, $this-&gt;pass, self::$settings);
    } catch (PDOException $e) {
        echo $e-&gt;getMessage();
    }
}
</code></pre>