There exists a database with a users
table containing 2 columns, userId
and saved
. userId
is a simple increment, and saved
is JSON data.
There exists a single row:
userId: 1, saved: "{"value": 1}"
When the following code is run on Windows
const mysql = require('mysql2');
async function start() {
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'database'
});
connection.query('SELECT saved FROM users WHERE userId = 1', function(err, results, fields) {
console.log(results);
})
}
start();
[ TextRow { saved: '{"value": 1}' } ]
is displayed on Windows
[ TextRow { saved: { value: 1 } } ]
is displayed on Linux
What exactly is going on here that parses my JSON on Linux but not on Windows?
The MySQL versions are both different
mysql Ver 14.14 Distrib 5.7.33, for Linux (x86_64)
mysql Ver 15.1 Distrib 10.4.17-MariaDB, for Win64 (AMD64)
I'm unsure how I'd get both of them to the same version. The Windows machine is running XAMPP and it seems like a pain to mess with. I'm trying right now to get the same versions of both installed.
The users
table is InnoDB utf8mb4_general_ci
field | type |
---|---|
userId | int(10) |
saved | longtext utf8mb4_bin |
I'm not actually using this code for anything, I use an ORM to do this but it uses mysql2 to do querying and I traced the error down to mysql2 and just copy-pasted the example code from GitHub to test if it was the culprit. I would use promise-based code if I was actually working with it.
MySQL2 is indeed the same version on both platforms. 2.2.5.
Interestingly the issue doesn't occur with the mysql package. I assume this indicates something funky going on with the package itself.