Home >Database >Mysql Tutorial >Why Am I Getting an 'ECONNREFUSED' Error When Connecting to MySQL with Node.js?
When attempting to connect to a MySQL server using Node.js, you might encounter the 'ECONNREFUSED' error. This error is commonly associated with the connection being refused by the server.
Potential Causes:
Solution:
If you have checked the potential causes and none of them apply, consider adjusting the port option in your connection parameters. Instead of specifying the TCP port, try specifying the path to the Unix socket using '/var/run/mysqld/mysqld.sock' as follows:
var mysql_link = { host: 'localhost', port: '/var/run/mysqld/mysqld.sock', // Unix socket path database: 'nodetest', user: 'root', password: 'xxx', }; var connection = mysql.createConnection(mysql_link);
The above is the detailed content of Why Am I Getting an 'ECONNREFUSED' Error When Connecting to MySQL with Node.js?. For more information, please follow other related articles on the PHP Chinese website!