title: Acces Denied errno: 1045 on POST method. Mysql 8 Nodejs
body: <p>I created a database in mysql, I have mysql 8 installed through homebrew.
  So far so good, I connect to the database without problems, but when I try to upload data to the database through an INSERT I get the following error::</p>
  <pre><code>[nodemon] 2.0.19
  [nodemon] to restart at any time, enter `rs`
  [nodemon] watching path(s): *.*
  [nodemon] watching extensions: js,mjs,json
  [nodemon] starting `node src/`
  Server on port: 4000
  DB is Connected!
  GET /expenses/add 200 35.845 ms - 1756
  GET /css/style.css 304 11.540 ms - -
  Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
      at Sequence._packetToError (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
      at Handshake.ErrorPacket (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
      at Protocol._parsePacket (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/protocol/Protocol.js:291:23)
      at Parser._parsePacket (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/protocol/Parser.js:433:10)
      at Parser.write (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/protocol/Parser.js:43:10)
      at Protocol.write (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/protocol/Protocol.js:38:16)
      at Socket.&lt;anonymous&gt; (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/Connection.js:88:28)
      at Socket.&lt;anonymous&gt; (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/Connection.js:526:10)
      at Socket.emit (node:events:513:28)
      at addChunk (node:internal/streams/readable:324:12)
      --------------------
      at Protocol._enqueue (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/protocol/Protocol.js:144:48)
      at Protocol.handshake (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/protocol/Protocol.js:51:23)
      at PoolConnection.connect (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/Connection.js:116:18)
      at Pool.getConnection (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/Pool.js:48:16)
      at Pool.query (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/mysql/lib/Pool.js:202:8)
      at node:internal/util:361:7
      at new Promise (&lt;anonymous&gt;)
      at Pool.query (node:internal/util:347:12)
      at /Users/manubrandes/Documents/proyects/El-Contador-1/src/routes/expenses.js:19:20
      at Layer.handle [as handle_request] (/Users/manubrandes/Documents/proyects/El-Contador-1/node_modules/express/lib/router/layer.js:95:5) {
    code: 'ER_ACCESS_DENIED_ERROR',
    errno: 1045,
    sqlMessage: &quot;Access denied for user 'root'@'localhost' (using password: NO)&quot;,
    sqlState: '28000',
    fatal: true
  }
  POST /expenses/add 200 9.534 ms - 18
  </code></pre>
  <p><strong>If you look first the connection works but then I get this error.</strong></p>
  <p>Here my code in database.js</p>
  <pre><code>const { Console } = require('console');
  const mysql = require('mysql');
  const { promisify } = require('util');
  
  const { database } = require('./keys'); 
  const pool = mysql.createPool(database);
  
  pool.getConnection((err,connection) =&gt; {
      if (err) {
          if (err.code === 'PROTOCOL_CONNECTION_LOST') {
              console.error('DATABASE CONNECTION WAS CLOSED');
          }
          if(err.code === 'ER_CON_COUNT_ERROR'){
              console.error('DATABASE HAS TO MANY CONNECTIONS')
          }
          if(err.code === 'ECONNREFUSED'){
              console.error('DATABASE CONNECTION WAS REFUSED')
          }
      }
  
      if (connection) connection.release();
      console.log('DB is Connected!');
      return;
  })
  
  pool.query = promisify(pool.query);
  
  module.exports = pool;
  </code></pre>
  <p>My keys.js archive</p>
  <pre><code>module.exports = {
      database: {
          connectionLimit : 100,
          host: '127.0.0.1',
          user: 'root',
          pass:'mypass',
          database: 'db_moneymanager'
          }
  }
  
  </code></pre>
  <p>And finally the file where I am making the post:</p>
  <pre><code>const express = require('express');
  const router = express.Router();
  
  //Conexion a la db
  const pool = require('../database');
  
  router.get('/add', (req, res) =&gt; {
      res.render('expenses/add');
  });
   
  router.post('/add', async(req, res) =&gt; {
      const { title, amount, description } = req.body;
      const newExpense = {
           title,
           amount,
           description
       };
      await pool.query('INSERT INTO outgoings set ?', [newExpense]);
      res.send('Received')
  });
  
  module.exports=router
  </code></pre>
  <p><strong>I already try this:</strong></p>
  <pre><code>CREATE USER 'manueldev'@'%' IDENTIFIED BY 'pepe';
  GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'manueldev'@'%' WITH GRANT OPTION;
  ALTER USER 'manueldev'@'%' IDENTIFIED WITH mysql_native_password BY 'pepe';
  </code></pre>
  <p>Thank you very much for taking the time to read the problem and try to give me a solution.</p>