search

Home  >  Q&A  >  body text

node.js - node连接mysql失败


利用node连接mysql一直连接不上,userpassword没有错误

ringa_leeringa_lee2782 days ago741

reply all(2)I'll reply

  • 阿神

    阿神2017-04-17 14:54:15

    Official example, follow this method to check out err. In addition to stack, you can also look at other contents, such as message, etc., and then locate the error.

    var mysql      = require('mysql');
    var connection = mysql.createConnection({
      host     : 'example.org',
      user     : 'bob',
      password : 'secret'
    });
     
    connection.connect(function(err) {
      if (err) {
        console.error('error connecting: ' + err.stack);
        return;
      }
     
      console.log('connected as id ' + connection.threadId);
    });

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 14:54:15

    Try writing down the port number too

    reply
    0
  • Cancelreply