'Ignoring invalid configuration option passed to Connection: root

I am getting started with mysql database for my NODEJS application const mysql = require('mysql2');

const pool = mysql.createPool({
  host: 'localhost',
  root: 'root',
  database:'node-complete',
  password: 'Pratik@123'
})

My root password is the one coded above.

I am getting this error:-

Ignoring invalid configuration option passed to Connection: root. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection

Can some help me to fix this issue?

module.exports = pool.promise()


Solution 1:[1]

the property in connection options must be named user, not root

const pool = mysql.createPool({
  host: 'localhost',
  user: 'root',
  database:'node-complete',
  password: 'Pratik@123'
});

Solution 2:[2]

you have to change the connection property root as user

const pool = mysql.createPool({ host:'localhost', user:'root', password:'admin',
database:'node-complete' })

Solution 3:[3]

I was getting the same problem, i used

const pool = mysql.createPool({
    host: 'localhost',
    username: 'root',
    database: 'node-complete',
    password: '24GM@L@PM+AU',
    port: '3306'
});

its not supposed to say "username" but instead just "user" like below

const pool = mysql.createPool({
    host: 'localhost',
    user: 'root',
    database: 'node-complete',
    password: '24GM@L@PM+AU',
    port: '3306'
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 slkorolev
Solution 2 bhuvi
Solution 3 Gee