mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Support MySQL official URI connection format (mysql://...)

Open NamanMahor opened this issue 3 months ago • 5 comments

Currently, the Go MySQL driver only supports the following DSN format:

user:password@tcp(localhost:3306)/dbname?param1=value1.

However, MySQL’s official documentation

defines a URI-based connection string format that looks like this:

mysql://user:password@localhost:3306/dbname?param1=value1

It would be useful if the driver could support the official URI scheme in addition to the current DSN format, for consistency with MySQL clients and other language drivers.

This would allow Go applications to accept and use standard MySQL connection URIs (e.g. from environment variables or config files) without having to reformat them.

NamanMahor avatar Sep 12 '25 16:09 NamanMahor

Can I work on this?

ayushdoesdev avatar Oct 31 '25 09:10 ayushdoesdev

@methane @julienschmidt @arnehormann , If this needs to be done then can I work on this?

ayushdoesdev avatar Oct 31 '25 09:10 ayushdoesdev

Of course, you can work on this. But whether to adopt it is another matter.

This is a breaking change for a lot of existing code. The first task will be to come up with a plan for everyone to migrate. After reviewing that plan, we will carefully and thoughtfully consider the pros and cons over time and decide whether to make the change.

methane avatar Oct 31 '25 10:10 methane

@methane Got it, thanks for the clarification! I’ll start looking into this and draft some initial ideas, but I’ll definitely need your input along the way. It would be really helpful if you could also add your thoughts or suggestions.

ayushdoesdev avatar Oct 31 '25 13:10 ayushdoesdev

One important thing to note here: this is not actually a "MySQL official URI connection format", nor is it a "standard". It's just an optional way to specify connection information for MySQL Shell (mysqlsh). As far as I know, no other "official" MySQL client programs from Oracle use this format so far, and nothing in MariaDB uses this format either.

Also in terms of the params, the ones supported by MySQL Shell inherently differ from what is supported by the Go driver. This may cause some confusion if implemented. Ditto for the way unix socket connections are specified in this scheme.

Edit to add: I'm partially mistaken above, I suppose one could correctly consider that URI format "official" based on its support in all the Oracle-supplied Connector drivers. However personally I still think this isn't widespread enough to justify well:

  • One motivator for Oracle creating this URI scheme was to support multiple protocols (classic mysql:// vs newer X protocol mysqlx://). But go-sql-driver/mysql does not support X protocol (see #478). Most third-party drivers (for any language) do not support it either. In any case, this motivation is not relevant here at this time.
  • Third-party drivers tend not to support this exact format, if they even support URIs at all.
  • Aside from mysqlsh, other official MySQL tools do not support URIs. For example mysql, mysqldump, mysqladmin all do not.

evanelias avatar Nov 25 '25 22:11 evanelias