skip to Main Content

Database connection working fine with localhost but not working with remote host.I got the ip from my cpanel that is shared ip. is there anything i am missing?

    const db = mysql.createConnection({
    host: '195.201.179.80',
    user: '****',
    password: '****',
    database: 'enamme_m-tube'
});
db.connect(function (err) {
    if (err) throw err
    console.log('Connection Established To Mysql Database')
})

Note: My Node app is running on localhost.

Error :

Error: connect ECONNREFUSED 195.201.179.80:3306
    at Object._errnoException (util.js:992:11)
    at _exceptionWithHostPort (util.js:1014:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)

2

Answers


  1. You should to connect to MYSQL under root and send query:

    GRANT ALL ON *.* TO <db_user>@<remote_ip> IDENTIFIED BY '<db_user_pass>';
    
    Login or Signup to reply.
  2. Did your mysqld binding on public IP address? As default mysqld will bind to the UNIX socket. Try adding this in your /etc/my.cnf

    [mysqld]
    bind-address = <your_public_ip>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search