Solve the Problem of connect ECONNREFUSED 127.0.0.1: 3306 in Node. js using MySQL, connecteconnrefused

Source: Internet
Author: User

Solve the Problem of connect ECONNREFUSED 127.0.0.1: 3306 in Node. js using MySQL, connecteconnrefused

Preface

Recently, I used Node to write a gadget that requires MySQL databases. Currently, the most widely used mysql database is used. Then, now the ORM is so popular, so I can't learn it, so I found the ORM library sequencee. js.

Problems Found

Let's take a look at sequencee's documentation. It's so easy. It's done in two minutes ~

Import sequencee from 'sequencee'; let sequencee = new sequencee ('database', 'username', 'Password', {host: 'localhost', port: 3306, dialect: 'mysql', pool: {max: 5, min: 0, idle: 10000 }});//... there is a bunch of questions behind it.

Run

SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306

What, why is this error? I set localhost clearly. Why is it 127.0.0.1?

Solve the problem

Google, as an example, has discovered that many people have encountered this problem. There are several solutions:

1. Do you think you can run it without installing MySQL? Install the database!

2. Is your database running? Run/etc/init. d/mysqld start.

3. Port Error

4. Have you enabled the skip-networking option? Remove it!

Here, I reflected that, because my database does not involve remote access, as long as Unix socket communication is enough, so skip-networking is enabled so that MySQL does not listen to the specified port.

What is skip-networking?

Do not listen for TCP/IP connections at all. all interaction with mysqld must be made using named pipes or shared memory (on Windows) or Unix socket files (on Unix ). this option is highly recommended for systems where only local clients are permitted.

Translation:

Do not listen to TCP/IP connections. All interactions with mysqld must use named pipes or shared memory (on Windows) or Unix socket files (on Unix ). We strongly recommend that you use this option for systems that only allow local clients.

Source

But for the sake of security, I don't want to remove this option. Do I have to endure the headache of Using ORM?

After reading the documentation, mysql Connection Library can use the socketPath attribute to specify Unix socket files, but sequencee. js does not find any relevant properties.

Finally, I had to issue an issue. Soon dalao replied that I could use dialectOptions to set mysql attributes.

The code for testing is as follows:

Import sequencee from 'sequencee'; let sequencee = new sequencee ('database', 'username', 'Password', {host: 'localhost', port: 3306, dialect: 'mysql', dialectOptions: {socketPath: '/tmp/mysql. sock '// specifies the socket file path} pool: {max: 5, min: 0, idle: 10000 }});

That's simple...

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.