errorError: getaddrinfo ENOTFOUND - mysql

前端 未结 5 1452
温柔的废话
温柔的废话 2021-01-18 01:17

I\'m running a server on c9.io using Node.js and trying to connect to Mysql I guess I get this error:

Error: getaddrinfo ENOTFOUND

5条回答
  •  走了就别回头了
    2021-01-18 01:43

    This code works for me.

    var mysql = require('mysql');
    
    var con = mysql.createConnection({
        host: '127.0.0.1',
        port: '3306',
        user: 'yourUsername',
        password: '**********'
    });
    
    con.connect(function(err){
        if(err) throw err;
        console.log('connected!');
    });
    

    the host and port name find them in your mysql server. in-place of '127.0.0.1' you can use 'localhost'

提交回复
热议问题