{"id":16812917,"url":"https://github.com/sjmudd/mysql_defaults_file","last_synced_at":"2025-04-11T01:43:54.679Z","repository":{"id":22891966,"uuid":"26240291","full_name":"sjmudd/mysql_defaults_file","owner":"sjmudd","description":"Access in GO to MySQL via a defaults_file","archived":false,"fork":false,"pushed_at":"2024-05-30T12:18:32.000Z","size":32,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T22:51:17.948Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sjmudd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-05T21:20:42.000Z","updated_at":"2024-08-24T14:29:57.000Z","dependencies_parsed_at":"2024-06-19T09:58:37.480Z","dependency_job_id":"57dc6335-73fd-4285-bae2-7484857f83e3","html_url":"https://github.com/sjmudd/mysql_defaults_file","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjmudd%2Fmysql_defaults_file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjmudd%2Fmysql_defaults_file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjmudd%2Fmysql_defaults_file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjmudd%2Fmysql_defaults_file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sjmudd","download_url":"https://codeload.github.com/sjmudd/mysql_defaults_file/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248327753,"owners_count":21085257,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T10:23:58.756Z","updated_at":"2025-04-11T01:43:54.662Z","avatar_url":"https://github.com/sjmudd.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## mysql_defaults_file\n\nAccess in Go to MySQL via a defaults_file.\n\nIf using the MySQL command line utilities such as `mysql` or\n`mysqladmin` you can provide a defaults-file option which stores\nthe credentials of the MySQL server you want to connect to. If no\nspecific defaults file is mentioned these utilities look in `~/.my.cnf`\nfor this file.\n\nThe Go sql interface does not support this functionality yet it can\nbe quite convenient as it avoids the need to explicitly provide credentials.\n\nThis small module fills in that gap by providing a function to allow you\nto connect to MySQL using a specified defaults-file, or using the\n`~/.my.cnf` if you do not specify a defaults-file path.\n\nThere is also a function BuildDSN which allows you to build up a Go\ndsn for MySQL using various entries in a mysql .ini file.\n\nThis logic could be simplified by using\ngithub.com/go-sql-driver/mysql.Config together with Config.FormatDSN(),\nbut there are a few minor differences in behaviour such as the\ndefault timezone handling using mysql.Config being UTC compared to\nmysql's command line client using the system timezone.\n\nThe functions provided are used by [ps-top](http://github.com/sjmudd/ps-top)\nto simplify the connectivity and have been split off from it as they\nmay be useful for other programs that connect to MySQL.\n\nThe code has been extended to handle quoted usernames and passwords,\nremoving whitespace and quotes if found. Quoting with single or\ndouble quotes is permitted.\n\n### Usage\n\nUsage:\n\n```\nimport (\n\t...\n\t\"database/sql\"\n\n\t_ \"github.com/go-sql-driver/mysql\"\n\t\"github.com/sjmudd/mysql_defaults_file\"\n\t...\n)\n\n// Get the DSN information from the defaults file, provide the\n// database to connect to and use sql.Open as normal\ndb, err = sql.Open(\"mysql\", mysql_defaults_file.DefaultDSN(\"\", \"mydb\"))\n\n// Get the DSN from a non-standard defaults file, provide the\n// database to connect to and use sql.Open as normal\ndb, err = sql.Open(\"mysql\", mysql_defaults_file.DefaultDSN(\"/path/to/.my.cnf\", \"mydb\"))\n\n// open the connection to the database using the default defaults-file (original way).\ndb, err = mysql_defaults_file.OpenUsingDefaultsFile(\"mysql\", \"\", \"performance_schema\")\n\n// open the connection to the database using the default defaults-file (shorter form).\ndb, err = mysql_defaults_file.Open(\"\", \"\")\n\n// open the connection to the database using a specific defaults-file and to mydb.\ndb, err = mysql_defaults_file.Open(\"/path/to/my.ini\", \"mydb\")\n```\n\nThe errors you get back will be the same as calling `sql.Open( \"mysql\",..... )`.\n\n### Licensing\n\nBSD 2-Clause License\n\n### Feedback\n\nFeedback and patches welcome.\n\nSimon J Mudd\n\u003csjmudd@pobox.com\u003e\n\n### Code Documenton\n[godoc.org/github.com/sjmudd/mysql_defaults_file](http://godoc.org/github.com/sjmudd/mysql_defaults_file)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjmudd%2Fmysql_defaults_file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsjmudd%2Fmysql_defaults_file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjmudd%2Fmysql_defaults_file/lists"}