title: typescript/node project: Client does not support authentication protocol requested by server
body: <p>I'm having an issue connecting to a mysql database which I'm running locally on my machine using a node server (also running locally).</p>
  
  <h2>Background Info / Setup</h2>
  
  <p>My node project is using typescript, but I am running it by running <code>tsc</code> then <code>npm run start</code> (aka, not using ts-node)</p>
  
  <p>I use typeORM to connect to the database running on my machine. Here is how i'm starting up the connection:</p>
  
  <pre class="lang-ts prettyprint-override"><code>import {createConnections} from "typeorm";
  import { runServer } from "./server";
  
  async function startServer(): Promise&lt;void&gt; {
  
      console.log("Starting server...");
      runServer();
  
      try {
          await createConnections();
      } catch (e) {
          throw e;
      }
  }
  
  startServer();
  </code></pre>
  
  <p>typeORM in their documentation included that createConnections() will try to use default connections, or any connections defined in ormconfig.js, which I have done:</p>
  
  <pre class="lang-js prettyprint-override"><code>// ormconfig.js
  module.exports = [{
      "name": "MySQL Local DB",
      "type": "mysql",
      "host": "localhost",
      "port": 3306,
      "username": "test_user",
      "password": "12345",
      "database" "test_db",
      "entities": ["entities/*.js"],
      "logging": true
  },
  ...
  // more db connections defined here for sqlite and other db's
  ]
  </code></pre>
  
  <h2>The Issue</h2>
  
  <p>When I run <code>npm run start</code> I get this error:</p>
  
  <pre><code>ER_DBACCESS_DENIED_ERROR: Access denied for user 'test_user'@'localhost' to database 'api'
  </code></pre>
  
  <p>To fix this issue I run <code>GRANT ALL PRIVILEGES ON test_db.* TO 'test_user'@'localhost';</code> followed by <code>FLUSH PRIVILEGES;</code></p>
  
  <p>After I execute this line, I get a new error: </p>
  
  <pre><code>ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
  </code></pre>
  
  <p>To fix this one I've tried running <code>ALTER USER 'test_user'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345';</code> followed by <code>FLUSH PRIVILEGES;</code> but I get the same error.</p>
  
  <p>I've tried a different version of this, where I create the user with <code>mysql_native_password</code> set by default, then try connecting, get the "cannot connect to db 'test_db'" message, then Grant all privileges on that db, but then I get the "Client does not support authentication protocol requested by server" error.</p>
  
  <h2>What I've tried:</h2>
  
  <ul>
  <li><p>various combinations of <code>GRANT ALL PRIVILEGES...</code> and <code>ALTER USER ... mysql_native_password</code>, with no success</p></li>
  <li><p>Doing a fresh install of mysql and running it as both a windows service and disabling run as service.</p></li>
  <li><p>Setting my security/authentication settings to Legacy in MySQL Server configuration</p></li>
  </ul>
  
  <h2>What might be the issue, but I haven't tried</h2>
  
  <p>I have a mysql-init.txt file running whenever I run mysqld to start the server, but all I do in that one is set the password for the root user and tell it to run using mysql_native_password, so I don't think it should be causing the issue.</p>
  
  <p>Sorry for the information dump. Hopefully its all useful.</p>