title: Laravel SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'
body: <p>I get this error in the browser on my test Laravel project:</p>
  <pre class="lang-none prettyprint-override"><code>Illuminate\Database\QueryException
  SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'
  (SQL: select count(*) as aggregate from `users` where `email` = test@test.com)
  </code></pre>
  <p>I have found similar problems in Stack Overflow and other sites, but all the solutions given never worked for me.</p>
  <p>Another similar error code refers to MySQL, but mine is about Laravel. Not MySQL. <br/>
  I use <a href="https://en.wikipedia.org/wiki/MySQL" rel="nofollow noreferrer">Ubuntu 18.04</a> (Bionic Beaver), Laravel 6, LAMP, my database is MySQL, the server is served by Apache 2.4, not Homebrew or PHP localhost.</p>
  <p>----------(test project context)</p>
  <p>I'm following a tutorial and I successfully added the LOGIN and REGISTER button. Now when I try to register a new user, I got two permission issues which I was able to solve with <code>sudo chmod</code>, but I have been stuck on this third problem for five hours now. I'm going to reinstall everything if I don't get this right by today.</p>
  <p>In my understanding <code>PHP ARTISAN UI:AUTH</code> takes care of all the code and you only need to <code>PHP ARTISAN MIGRATE</code> after creating the authorization UI which I already did. I can actually see the tables <code>MIGRATE</code> created in database in the MYSQL terminal.</p>
  <p>----------(/test project context)</p>
  <p>Solutions I've tried:</p>
  <pre class="lang-none prettyprint-override"><code>DB_CONNECTION=mysql
  DB_HOST=127.0.0.1 or 127.0.0.11 or localhost
  DB_PORT=3306 or 33060
  DB_DATABASE=test
  DB_USERNAME=root or I_created_a_new_user_with_all_privileges
  DB_PASSWORD=password
  </code></pre>
  <p>I've tried matching my database configuration in the <em>app\config\database.php</em> file in Laravel.</p>
  <p>I already <code>sudo chmod 777 /var/www/html/blog</code> out of desperation.</p>
  <p>I tried a bunch of clears in the terminal.</p>
  <pre class="lang-none prettyprint-override"><code>php artisan config:cache
  php artisan config:clear
  php artisan cache:clear
  </code></pre>
  <p>This is <em>app\config\database.php</em> file:</p>
  <pre class="lang-none prettyprint-override"><code>'mysql' =&gt; [
              'driver' =&gt; 'mysql',
              'url' =&gt; env('DATABASE_URL'),  &lt;--- NEVER TRIED THIS PART THOUGH, idk what to put
              'host' =&gt; env('DB_HOST', '127.0.0.1'), &lt;---- tried all
              'port' =&gt; env('DB_PORT', '3306'),      &lt;---- tried 33060
              'database' =&gt; env('DB_DATABASE', 'forge'), &lt;--- tried 'test' as my DB
              'username' =&gt; env('DB_USERNAME', 'forge'), &lt;--- tried 'root' or 'nico'
              'password' =&gt; env('DB_PASSWORD', ''), &lt;--- 'password'
              'unix_socket' =&gt; env('DB_SOCKET', ''),
              'charset' =&gt; 'utf8mb4',      &lt;--- tried 'utf8'
              'collation' =&gt; 'utf8mb4_unicode_ci',
              'prefix' =&gt; '',
              'prefix_indexes' =&gt; true,
              'strict' =&gt; true,
              'engine' =&gt; null,
              'options' =&gt; extension_loaded('pdo_mysql') ? array_filter([
                  PDO::MYSQL_ATTR_SSL_CA =&gt; env('MYSQL_ATTR_SSL_CA'),
              ]) : [],
          ],
  </code></pre>
  <p>I already checked the owners of the file and the programs. It's either <em>root</em> or <em>www-data</em> and made sure that Apache2 is ran by <em>root</em> or <em>www-data</em> either or both. I used <code>ps aux | grep apache</code>.</p>
  <p>I never had this problem in Windows 10 WAMP stack. I'm at my wits end.</p>
  <p>I recreated the project from scratch, but I still get the same error.</p>
  <p>This article solved it: <em><a href="https://askubuntu.com/questions/998920/1698-access-denied-for-user-rootlocalhost-mysql-5-7-and-ubuntu-16-04">#1698 - Access denied for user 'root'@'localhost' mysql -5.7 and ubuntu-16.04</a></em></p>
  <pre class="lang-none prettyprint-override"><code>Step 1. `sudo mysql -u root -p`
  
  Step 2. `USE mysql;`
  
  Step 3. `ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'admin';`
  
  Here 'admin' is your new password, but you can change it.
  
  Step 4. Exit Thanks. You are done.
  </code></pre>