question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can connect from mysql cli, but not from node-mysql2

See original GitHub issue

I’ve been getting a “host not allowed to connect error” that completely baffles me, as connecting from the mysql command line interface using the same parameters works fine. I boiled it down to the simplest possible setup for testing:

var mysql = require("mysql2");

var db = mysql.createConnection({
    "database": "database",
    "user": "user",
    "password": "xxxxxxx",
    "host": "yyy.yyy.yyy.yyy",
    "insecureAuth":true,
    "debug":true,
    "ssl": {
        "rejectUnauthorized":false
    }
});

db.connect();
db.query("SELECT * FROM table LIMIT 1", function(err, res) {});
db.end();

The insecureAuth and ssl options were meant to help eliminate server-side issues. The same error occurs with or without them.

Running this with node test.js results in:

0 undefined ==> Connection#handshakeInit(0,Error,70)
 raw: ff6a04486f737420273137332e33302e38332e32343927206973206e6f7420616c6c6f77656420746f20636f6e6e65637420746f2074686973204d7953514c20736572766572
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Host 'zzz.zzz.zzz.zzz' is not allowed to connect to this MySQL server
    at Packet.asError (/home/nphyx/Dropbox/dev/fbradius/node_modules/mysql2/lib/packets/packet.js:493:13)
    at ClientHandshake.Command.execute (/home/nphyx/Dropbox/dev/fbradius/node_modules/mysql2/lib/commands/command.js:25:22)
    at Connection.handlePacket (/home/nphyx/Dropbox/dev/fbradius/node_modules/mysql2/lib/connection.js:310:28)
    at PacketParser.onPacket (/home/nphyx/Dropbox/dev/fbradius/node_modules/mysql2/lib/connection.js:83:65)
    at PacketParser.executeStart (/home/nphyx/Dropbox/dev/fbradius/node_modules/mysql2/lib/packet_parser.js:39:12)
    at Socket.<anonymous> (/home/nphyx/Dropbox/dev/fbradius/node_modules/mysql2/lib/connection.js:95:31)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:538:20)

However if I do:

$ mysql -u user -p -h yyy.yyy.yyy.yyy --database database
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 260318
Server version: 5.5.41-MariaDB-log MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

I connect successfully and am able to run queries per the permissions configured on the mysql server.

The server is not configured to require/use SSL. It is running on the standard (3306) port and listening on the external interface, as the cli results indicate.

Local host info:

$ uname -a
Linux jormungandr 3.19.3-3-ARCH #1 SMP PREEMPT Wed Apr 8 14:10:00 CEST 2015 x86_64 GNU/Linux
$ node --version
v0.12.2

Any thoughts? I’m on a tight deadline here so please let me know if you need anything else.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
1801256646commented, Jun 14, 2022

good

0reactions
sidorarescommented, May 14, 2015

no problems, good luck with the rest!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can connect to remote mysql DB through mysql workbench ...
I'm trying to connect my NodeJS application ...
Read more >
Connecting to the MySQL Database Server from Node.js
This tutorial shows you how to connect to the MySQL database server from a node.js application using the mysql module API.
Read more >
Node.js Connect Mysql with Node app - GeeksforGeeks
In this article, we will learn how to connect the Mysql database to the NodeJs application. Before we go deep into the coding...
Read more >
How to Connect a Node Application to a MySQL Database
The mysql2 package makes connecting to a database from Node straightforward. Learn all about it.
Read more >
Node.js MySQL - W3Schools
Start by creating a connection to the database. Use the username and password from your MySQL database. ... Which will give you this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found