简体   繁体   中英

Mysql and NodeJS can't connect remotely to deployed app

I am trying to connect from a NodeJS app to a MySQL database (already deployed, not in a localhost), currently it throws an error saying:

Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'user'@'187.189.130.120' (using password: YES)
    at Handshake.Sequence._packetToError (C:\wamp\Respaldo Linux\Documentos\WebDev\misGastosApp\node_modules\mysql\lib\protocol\sequences\Sequence.js:48:14)
    at Handshake.ErrorPacket (C:\wamp\Respaldo Linux\Documentos\WebDev\misGastosApp\node_modules\mysql\lib\protocol\sequences\Handshake.js:101:18)
    at Protocol._parsePacket (C:\wamp\Respaldo Linux\Documentos\WebDev\misGastosApp\node_modules\mysql\lib\protocol\Protocol.js:271:23)
    at Parser.write (C:\wamp\Respaldo Linux\Documentos\WebDev\misGastosApp\node_modules\mysql\lib\protocol\Parser.js:77:12)
    at Protocol.write (C:\wamp\Respaldo Linux\Documentos\WebDev\misGastosApp\node_modules\mysql\lib\protocol\Protocol.js:39:16)
    at Socket.<anonymous> (C:\wamp\Respaldo Linux\Documentos\WebDev\misGastosApp\node_modules\mysql\lib\Connection.js:82:28)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:748:14)
    at Socket.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:410:10)
    --------------------
    at Protocol._enqueue (C:\wamp\Respaldo Linux\Documentos\WebDev\misGastosApp\node_modules\mysql\lib\protocol\Protocol.js:135:48)
    at Protocol.handshake (C:\wamp\Respaldo Linux\Documentos\WebDev\misGastosApp\node_modules\mysql\lib\protocol\Protocol.js:52:41)
    at Connection.connect (C:\wamp\Respaldo Linux\Documentos\WebDev\misGastosApp\node_modules\mysql\lib\Connection.js:109:18)
    at Object.<anonymous> (C:\wamp\Respaldo Linux\Documentos\WebDev\misGastosApp\app.js:87:12)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

If I log into my cpanel account and then add my public IP to MySQL remote connections, I am able to connect the app with the MySQL database, but I want to know how could I make it work for when the app is in production. I already read that many users grant all privileges for a user, which already did and still the same (can't connect).

I also read that I could grant remote access to an IP with a wildcard but if I do this, I would need to grant access for all IPs in Mexico? I been reading many things trying to accomplish this connection. My main goal is within production, being able to download the app to my phone (or anyone's phone), then access the app and connect to MySQL. This is because I need constantly check if the data is new and then sync to MySQL. Also I have some doubts if allowing remote MySQL connections would be a security issue?

Note: This is my first app with sync and NodeJS-MySQL, so any advice is really appreciated.

This is not a NodeJS issue. You have not granted your "user" access to the database from all hosts.

http://dev.mysql.com/doc/refman/5.1/en/grant.html

Something like this in mysql shell:

GRANT SELECT ON db.* TO 'user'@'%'

% represents ALL hosts not just a single one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM