why TypeOrm is not connect to MySQL in digital ocean server

Posted September 24, 2020 1.5k views
[TypeOrmModule] Unable to connect to the database. Retrying (5)... +3004ms
Error: connect ECONNREFUSED
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
    at Protocol._enqueue (/var/www/myapp/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/var/www/myapp/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at PoolConnection.connect (/var/www/myapp/node_modules/mysql/lib/Connection.js:116:18)
    at Pool.getConnection (/var/www/myapp/node_modules/mysql/lib/Pool.js:48:16)
    at /var/www/myapp/node_modules/typeorm/driver/mysql/MysqlDriver.js:794:18
    at new Promise (<anonymous>)
    at MysqlDriver.createPool (/var/www/myapp/node_modules/typeorm/driver/mysql/MysqlDriver.js:791:16)
    at MysqlDriver.<anonymous> (/var/www/myapp/node_modules/typeorm/driver/mysql/MysqlDriver.js:278:51)
    at step (/var/www/myapp/node_modules/tslib/tslib.js:136:27)
    at (/var/www/myapp/node_modules/tslib/tslib.js:117:57)
    at /var/www/myapp/node_modules/tslib/tslib.js:110:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/var/www/myapp/node_modules/tslib/tslib.js:106:16)
    at MysqlDriver.connect (/var/www/myapp/node_modules/typeorm/driver/mysql/MysqlDriver.js:263:24)
    at Connection.<anonymous> (/var/www/myapp/node_modules/typeorm/connection/Connection.js:112:58)
    at step (/var/www/myapp/node_modules/tslib/tslib.js:136:27)
edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


As you are connecting from an external server, you need to allow remote connections for your MySQL server.

You can follow the steps on how to do that here:


by Mark Drake
Many websites and applications start off with their web server and database backend hosted on the same machine. With time, though, a setup like this can become cumbersome and difficult to scale. A common solution is to separate these functions by setting up a remote database, allowing the server...