Search code examples
javascriptmysqlnode.jsprotocols

Connect to mysql from nodeJS with NO dependencies at all


I've seen various questions on here as well as the npm library https://www.npmjs.com/package/mysql

Which is even recommended by w3schools, but i haven't been able to find any information on making a mysql client from just plain native nodejs (using the .net module only if needed)

In aware that mysql doesn't communicate by means of http requests, but rather some other kind of socket, i haven't been able to find the specifications for this protocol, nor any tutorials that explain how to implement it with nodejs


Solution

  • The MySQL Client/Server Protocol is documented here:

    https://dev.mysql.com/doc/internals/en/client-server-protocol.html

    That's the only resource I know of. I know it's out of date, but the concepts in it are a good introduction.

    Frankly, every project that develops their own implementation of the MySQL protocol do so by reading the code. The code is by definition the most accurate and up to date representation of the protocol.

    The changes to the MySQL protocol are incremental. What you learn from that documentation will help you understand the code.

    This is not the kind of project that has a tutorial. The audience of potential readers is so small that it wouldn't be worth developing a tutorial.

    I know of a few implementations of the MySQL protocol. For example:

    • libmysqlclient, which is the client library included in the MySQL source code. This is written in C.
    • PHP's mysqlnd extension, which is also written in C, but it's a separate implementation because it's licensed differently.
    • MySQL Connector/J, which is a Java implementation of the client.
    • mysqljs, which is a Node.js implementation of the MySQL protocol in 100% javascript. This may be exactly what you propose to develop. But using it would technically be a dependency.

    Frankly, I would just use one of the existing implementations. Developing a new implementation is bound to take months, even if you had strong understanding of the protocol already. It's meticulous work.