blackbeam / rust-mysql-simple

Mysql client library implemented in rust.
Apache License 2.0
665 stars 146 forks source link

how to use a unix domain socket in the DSN #181

Closed nbari closed 5 years ago

nbari commented 5 years ago

I am trying to use a DSN like this:

 mysql://root:example@unix:/my/pah/mysqld.sock

or

 mysql://root:example@/my/pah/mysqld.sock

But get this error:

{ Could not connect to address `unix:3306': failed to lookup address information: Name or service not known }

I am using from_url like this:

let opts = mysql::Opts::from_url(matches.value_of("DSN").unwrap()).unwrap_or_else(|e| {
        eprintln!("verify the DSN: {}", e);
        process::exit(1);
    });
let mut opts = mysql::OptsBuilder::from_opts(opts);

It is possible to pass the path of the Unix socket when using from_url if yes could you please share an example?

blackbeam commented 5 years ago

Hi.

There is no way to specify socket path via DSN. Please use OptsBuilder::prefer_socket and OptsBuilder::socket.

nbari commented 5 years ago

Maybe this could be a nice enhancement what about:

let opts = mysql::Opts::from_dsn("...")

or

let opts = mysql::Opts::DSN("...")

or any idea of a library that could parse a DSN?, my goal is to simplify the input from the users, something like https://github.com/go-sql-driver/mysql#dsn-data-source-name

blackbeam commented 5 years ago

Thanks. I'll look into it.