Skip to content

Unix socket requires user and password #2334

Open
@abramsba

Description

@abramsba

Possibly similar issue

#2142

Node: v13.13.0
Mysql Library: 2.18.1
Mysql (mariadb) version: 10.4.12
OS: Arch Linux

I'm not connecting using url/pass/user, but using a socket. It seems I always have to supply a user and password even if I'm using a socket file and running it from the same user. I would think I dont need to supply a user and password because it is based on file permission of the user who started the node process, but maybe this assumption is wrong.

Simple example:

[bryan]$ sudo su
[root]$ mysql
...
> create database test;
> use test;
> create table testing (id int);
> \q

Create a new application:

yarn init -y
yarn add mysql

And this code:

const mysql = require('mysql')
// run mysql-config --socket 
const conn = mysql.createConnection({ socket: '/run/mysqld/mysqld.sock' })
conn.query('select 1', (error, results, columns) => {
  console.log(results)
  conn.query('use test', console.log)
})

If I run this, I see the results from the select 1 query so it's made a connection. When it gets to the second statement use testing, or if I use any statement like select testing.table I get an access denied error:

Error: ER_DBACCESS_DENIED_ERROR: Access denied for user ''@'localhost' to database 'testing'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions