connect ECONNREFUSED - node js , sql

前端 未结 3 1129
走了就别回头了
走了就别回头了 2020-11-28 15:24

I have the next code in a js file:

var mysql = require(\'mysql\');
var TEST_DATABASE = \'nodejs_mysql_test\';
var TEST_TABLE = \'test\';
var         


        
相关标签:
3条回答
  • 2020-11-28 15:46

    I know two ways to solve it:

    1. In mysql.conf, comment skip-networking.

    2. Try to set the socket like this:

      var client = mysql.createClient({
      user: uuuu,
      password: pppp,
      host: '127.0.0.1',
      port: '3306',
      _socket: '/var/run/mysqld/mysqld.sock',});
      
    0 讨论(0)
  • 2020-11-28 15:49

    I got this error when MySQL Server was not running.

    I changed my configuration via Initialize Database in MySQL.PrefPane, the System Preferences tool for MySQL on OS X - to Use Legacy Password Encryption - to fix ER_NOT_SUPPORTED_AUTH_MODE. This config change stopped MySQL Server and then I got ECONNREFUSED when I tried to connect to MySQL from node.js.

    Fixed by restarting MySQL Server from the MySQL System Preferences tool.

    0 讨论(0)
  • 2020-11-28 15:50

    Try to fix your defined port in mysql and your Node.js script. You can define the mysqld port in the *.cnf file inside the mysql directory, and you can define that port when you connect to MySQL in your Node.js script.

    Something like this in the cnf file

    port = 3360
    
    0 讨论(0)
提交回复
热议问题