mysqldvibed

Failing to connect to MySQL in Dlang with vibe-d and mysql-native


I have simple vibe-D program which is trying to connect to SQL:

import std.stdio;
import mysql;
import vibe.d;
void main()
{
  MySQLPool db_pool = new MySQLPool("localhost","root","","dbname",3306);
  Connection db = db_pool.lockConnection();
  // same thing happens with:
  // string connectionStr = "host=localhost;port=3306;user=root;db=dbname";
  // db = new Connection(connectionStr);
}

(I deleted everything else for simplification)

Dependencies:

"dependencies": {
  "mysql-native": "~>3.2.0",
  "vibe-d": "~>0.9.4"
}

And it fails to connect with:

object.Exception@../../../.dub/packages/vibe-core-1.22.4/vibe-core/source/vibe/core/net.d(256): Failed to connect to [0:0:0:0:0:0:0:1]:3306: refused

When I try it without vibe-d in the dub project (using phobos sockets) it connects with no problem. What am I doing wrong?


Solution

  • that's an ipv6 address.... is your mysql listening on that interface? might help trying 127.0.0.1 instead of localhost and seeing what happens.

    can also consider reconfiguring mysql to listen on all interfaces too, including the ipv6