2

I just downloaded MariaDB 10.3 for Windows ,created a database and trying to connect from a NodeJS server using mysql library.

var mysql = require('mysql');
var con = mysql.createConnection({
  host: "localhost", 
  user: "root",
  password: "MariaDBPass",
  database:'DB_NAME',
});

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
  con.query(sql, function (err, result) {
    if (err) throw err;
    console.log("Result: " + result);
  });
});

I tried it on Ubuntu and it's working but on windows it throws an non-sql error:

Client does not support authentication protocol requested by server; consider upgrading MariaDB client

I've red that maybe it is an incompatibility between MySQL 8.0 and the library(mysql). I've already tried to alter the user as following :

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'

but it said that

there is an SQL Syntax Error

Any ideas on how to solve this?

SuperStar518
  • 2,814
  • 2
  • 20
  • 35

1 Answers1

0

I don't know how helpful this will be, but using the following setup:

  • MariaDB 10.3 (x64)
  • Windows 10 Pro (build 17763)
  • mysql module v2.16.0.
  • Node.js v10.15.1

The following code works as expected for me:

var mysql = require('mysql');
var con = mysql.createConnection({
    host: "localhost", 
    user: "some_user",
    password: "some_password",
    database: 'testdb'
});

let sql = "select * from test_table";

con.connect(function(err) {
    if (err) throw err;
    console.log("Connected!");
    con.query(sql, function (err, result) {
        if (err) throw err;
        console.log("Result: " + JSON.stringify(result));
    });
});

I get an output like:

[{"id":1,"name":"Mike Smith"},{"id":2,"name":"Joe Brown"}]

To create the user I did (using MariaDB mysql.exe, using root user):

use testdb;

create user 'some_user'@'localhost' identified by 'some_password';

grant all privileges on testdb.* to 'some_user'@'localhost';

This is maybe a little permissive, but it's ok for testing connections.

I can also connect with the root user.

If you wish to set the root user password, try:

use mysql;

update user set password=PASSWORD('password') where user='root'and host='localhost';

flush privileges;

I created a simple db 'testdb' and table 'test_table' with a couple of rows to use for queries.

I'd suggest perhaps upgrading your mysql module version if you can. Also maybe look at the Node.js version.

Terry Lennox
  • 29,471
  • 5
  • 28
  • 40