mysql
mysql copied to clipboard
Unix socket requires user and password
Possibly similar issue
https://github.com/mysqljs/mysql/issues/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'
but maybe this assumption is wrong.
this depends on the auth plugin configured and not on the tcp vs socket transport. What you describe can be achieved for example using socket_auth plugin. You can check what plugin is configured for you with select user, plugin from mysql.user where user = '<your_user_goes_here>'
query
Running that query I get mysql_native_password
. I followed the plugin guide, but that query isn't working either:
> INSTALL SONAME "auth_socket";
ERROR 1126 (HY000): Can't open shared library '/usr/lib/mysql/plugin/auth_socket.so' (errno: 2, cannot open shared object file: No such file or directory)
EDIT: Should add that socket authentication has to be enabled somehow because mysql
without giving credientials connects via unix socket
Since the guide said it comes by default, I checked the package and saw that auth_socket.so
isn't there: https://www.archlinux.org/packages/extra/x86_64/mariadb/
Though I'm not sure why. In either case I'll try on Ubuntu.