title: php mysqli_connect: authentication method unknown to the client [caching_sha2_password]
body: <p>I am using php <code>mysqli_connect</code> for login to a MySQL database (all on localhost)</p>
  
  <pre><code>&lt;?php
  //DEFINE ('DB_USER', 'user2');
  //DEFINE ('DB_PASSWORD', 'pass2');
  DEFINE ('DB_USER', 'user1');
  DEFINE ('DB_PASSWORD', 'pass1');
  DEFINE ('DB_HOST', '127.0.0.1');
  DEFINE ('DB_NAME', 'dbname');
  
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  
  if(!$dbc){
      die('error connecting to database');    
  }
  ?&gt;
  </code></pre>
  
  <p>this is the mysql.user table:
  <a href="https://i.stack.imgur.com/fyMXv.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/fyMXv.jpg" alt="mysql.user table"></a></p>
  
  <p>MySQL Server ini File:</p>
  
  <pre><code>[mysqld]
  # The default authentication plugin to be used when connecting to the server
  default_authentication_plugin=caching_sha2_password
  #default_authentication_plugin=mysql_native_password
  </code></pre>
  
  <p>with <code>caching_sha2_password</code> in the MySQL Server ini file, it's not possible at all to login with user1 or user2;</p>
  
  <blockquote>
    <p>error: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in...</p>
  </blockquote>
  
  <p>with <code>mysql_native_password</code> in the MySQL Server ini file, it's possible to login with user1, but with user2, same error;</p>
  
  <hr>
  
  <p>how can I login using <code>caching_sha2_password</code> on the mySql Server?</p>