mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Add support to read from another config file in the DSN

Open guillemj opened this issue 5 years ago • 2 comments

There is no support for reading a mysql configuration file as specified in the DSN. This is supported in other language bindings as read_default_file (or mysql_read_default_file). See https://bugs.mysql.com/bug.php?id=57081 for various examples. This is also supported as part of the C client library https://dev.mysql.com/doc/refman/8.0/en/mysql-options.html with its MYSQL_READ_DEFAULT_FILE option.

This makes it possible to specify for example the user and password (and host and port) in a central place, with tight file permissions instead of having to write these in places that are less desirable. In our case, we need to write the user/pass in the telegraf.conf file, and restrict the permissions, and duplicate the credentials that otherwise would be centralized in a single file.

guillemj avatar Nov 06 '19 16:11 guillemj

This can be implemented by writing another sql.Driver that wraps the the original driver.

As a demonstration, see my own driver github.com/dolmen-go/mylogin-driver that reads host/port/user/password from ~/.mylogin.cnf.

dolmen avatar Jun 01 '20 14:06 dolmen

That would require patching/forking any upstream that uses this package to use something else, which seems rather undesirable. :)

guillemj avatar Jun 01 '20 22:06 guillemj