Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to use "/" in the name of DB. What should I do? #1193

Closed
oshiro3 opened this issue Mar 2, 2021 · 7 comments
Closed

I want to use "/" in the name of DB. What should I do? #1193

oshiro3 opened this issue Mar 2, 2021 · 7 comments

Comments

@oshiro3
Copy link

oshiro3 commented Mar 2, 2021

Issue description

I want to use "/" in the DSN for the database name, such as xxx/yyy, but I get the error invalid DSN: did you forget to escape a param value? .
Using url.Escape () will evaluate the database name as xxx%2Fyyy.
How should I solve it?

I use go-sql-driver through golang-migrate/migrate library.

Example code

sql.Open("mysql", "user@tcp(host:port)/xxxx/yyy")

Error log

invalid DSN: did you forget to escape a param value?

Configuration

Driver version (or git SHA):

v1.5.0

Go version: run go version in your console

go1.15.3

Server version: E.g. MySQL 5.6, MariaDB 10.0.20

MySQL 5.7

Server OS: E.g. Debian 8.1 (Jessie), Windows 10

MacOS Catalina

@ghost
Copy link

ghost commented Apr 20, 2021

xxx/yyy for the database name is not a valid DSN value so it won't work.
This is the DSN format

[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]

As for the database name you have to remove the extra slash - /xxxyyy

@zihengCat
Copy link
Contributor

@oshiro3
Sorry, you couldn't use a slash / in your db name because of DSN format parsing mechanism.

And a database name which contains slash / is really bad in my personal thought. :(

@zihengCat
Copy link
Contributor

This issue could be closed safely.

@oshiro3
Copy link
Author

oshiro3 commented Jul 16, 2021

@zihengCat @evergreen-trading-systems
Thank you for the answer!
I just want to know, is invalid based on the DSN specification, or is it invalid as an implementation specification in go-sql-driver?
If there is an official DSN specification, please let us know.
I looked for it but couldn't find it...

@zihengCat
Copy link
Contributor

zihengCat commented Jul 16, 2021

@oshiro3
It's go-sql-driver implementation specified. The driver defined the rule that a valid DSN must follows:

[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]

There is no official DSN specification, Go team leave driver implementers define their own DSN format, which is much suitable and flexible for driver implementing.

@dolmen
Copy link
Contributor

dolmen commented Oct 17, 2023

To see what ParseDSN expects, the best is to fill a Config (use NewConfig) with your settings and call its FormatDSN method to see what it outputs.

Here is a template: https://go.dev/play/p/8E3WFHsTTJc

@dolmen
Copy link
Contributor

dolmen commented Oct 18, 2023

This has been fixed by #1432.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants