0

i need to connect to remote mysql database from my nodejs appliacation. Below is my code.

const mysqlssh = require('mysql-ssh');
 
mysqlssh.connect(
    {
        host: '572.168.0.68', //ssh login ip
        user: 'root',             // ssh username
        password:'password'   //ssh password
     
    },
    {
        host: '572.168.0.68', //ssh login ip
        user: 'dbusername',
        password: 'dbpassword',
        database: 'mydb'
    }
)
.then(client => {
    client.query('SELECT * FROM `dbtable`', function (err, results, fields) {
        if (err) throw err
        console.log(results);
        mysqlssh.close()
    })
})
.catch(err => {
    console.log(err)
})

I am getting the below error for the above code

 code: 'ER_ACCESS_DENIED_ERROR',
  errno: 1045,
  sqlState: '28000',
  sqlMessage: "Access denied for user 'dbusername'@'192.168.0.223' (using password: YES)"

const mysqlssh = require('mysql-ssh');

mysqlssh.connect(
    {
        host: '572.168.0.68', //ssh login ip
        user: 'root',             // ssh username
        password:'password'   //ssh password
     
    },
    {
         host: '572.168.0.68', //ssh login ip
        user: 'root',   // ssh login username
        password: 'dbpassword',
        database: 'mydb'
    }
)
.then(client => {
    client.query('SELECT * FROM `dbtable`', function (err, results, fields) {
        if (err) throw err
        console.log(results);
        mysqlssh.close()
    })
})
.catch(err => {
    console.log(err)
})

i am getting the below error for my above set up.

{
  code: 'ER_NOT_SUPPORTED_AUTH_MODE',
  errno: 1251,
  sqlState: '08004',
  sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client'
}

I am able to login to my mysql instance via putty using the same credentials given in the code. so what is the right way to connect to a remote mysql database with nodejs?

Jagadeesh
  • 1,967
  • 8
  • 24
  • 47
  • 1
    It's pretty difficult to understand without looking under the hood of `mysql-ssh` module, but I assume it actually establishes SSH connection using the credentials in the first object, and then connects to the DB. I would assume you need to set your DB host to `127.0.0.1` or `localhost` – Alex Shchur Jul 20 '20 at 07:05
  • I think there is something working in credentials only. Can you confirm the host? – xMayank Jul 20 '20 at 07:06
  • it worked thanx.. my db object has to be 127.0.0.1 .. – Jagadeesh Jul 20 '20 at 07:21
  • but the connection got established for one particular mysql username and password. but for other user i am still getting "{ code: 'ER_NOT_SUPPORTED_AUTH_MODE', errno: 1251, sqlState: '08004', sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client' }" – Jagadeesh Jul 20 '20 at 07:41

0 Answers0