[SOLVED] Can't connect to WPDB from Node.js

Hi all,

I’m trying to connect to the WPDB of Local from a Node.js app on my localhost, but I’m getting this error:

...
  code: 'ER_HOST_NOT_PRIVILEGED',
  errno: 1130,
  sqlMessage: "Host '127.0.0.1' is not allowed to connect to this MySQL server",
  sqlState: undefined,
  fatal: true
}

This is the piece of code that I’m using:

var mysql = require('mysql');

var connection = mysql.createConnection({
    host: '127.0.0.1',
    port: '10010',
    user: 'root',
    password: 'root',
    database: 'local',
});

connection.connect();

Any ideas, what is going on and how can I fix it?

Hi @lokal,

What operating system are you running? Local only allows accessing the server using a port on Windows.

If you’re on macOS or Linux, you’ll need to connect using the socket provided under the Database tab in the Local site.

Hi @clay,
thanks for the quick response!

What operating system are you running?

I’m on Linux.

Indeed! It worked by replacing host and port with socketPath option.

Thanks again!

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.