mysql
mysql copied to clipboard
Add support to read from another config file in the DSN
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.
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
.
That would require patching/forking any upstream that uses this package to use something else, which seems rather undesirable. :)