We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Check MySQL and Postgres credential files
In addition to allowing users to directly provide their MySQL and PostgreSQL credentials, it should also be possible for them to store these credentials in the usual places.

We should check information given by the user to the retriever first, and then fall back on the configuration files for usernames and passwords if they are not provided.

For PostgreSQL this is `~/.pgpass` with the format:

```
hostname:port:database:username:password 
```

See: https://wiki.postgresql.org/wiki/Pgpass. `*`s can be used in place of any of the `:` separated values.

For MySQL this is `~/.my.cnf` with the format:

```
[client]
user = root
password = yourpassword
```

See: https://dev.mysql.com/doc/refman/5.5/en/option-files.html. `.my.cnf` can contain a lot of additional configuration information so we'll need to look explicitly for `user =` and `password =`.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `retriever/engines/mysql.py`
Content:
```
1 from __future__ import print_function
2 from builtins import str
3 import os
4 from retriever.lib.models import Engine, no_cleanup
5 from retriever import ENCODING
6 
7 
8 class engine(Engine):
9     """Engine instance for MySQL."""
10     name = "MySQL"
11     abbreviation = "mysql"
12     datatypes = {
13         "auto": "INT(5) NOT NULL AUTO_INCREMENT",
14         "int": "INT",
15         "bigint": "BIGINT",
16         "double": "DOUBLE",
17         "decimal": "DECIMAL",
18         "char": ("TEXT", "VARCHAR"),
19         "bool": "BOOL",
20     }
21     max_int = 4294967295
22     placeholder = "%s"
23     required_opts = [("user",
24                       "Enter your MySQL username",
25                       "root"),
26                      ("password",
27                       "Enter your password",
28                       ""),
29                      ("host",
30                       "Enter your MySQL host",
31                       "localhost"),
32                      ("port",
33                       "Enter your MySQL port",
34                       3306),
35                      ("database_name",
36                       "Format of database name",
37                       "{db}"),
38                      ("table_name",
39                       "Format of table name",
40                       "{db}.{table}"),
41                      ]
42 
43     def create_db_statement(self):
44         """Returns a SQL statement to create a database."""
45         createstatement = "CREATE DATABASE IF NOT EXISTS " + self.database_name()
46         return createstatement
47 
48     def insert_data_from_file(self, filename):
49         """Calls MySQL "LOAD DATA LOCAL INFILE" statement to perform a bulk
50         insert."""
51 
52         mysql_set_autocommit_off = """SET autocommit=0; SET UNIQUE_CHECKS=0; SET FOREIGN_KEY_CHECKS=0; SET sql_log_bin=0;"""
53         mysql_set_autocommit_on = """SET GLOBAL innodb_flush_log_at_trx_commit=1; COMMIT; SET autocommit=1; SET unique_checks=1; SET foreign_key_checks=1;"""
54         
55         self.get_cursor()
56         ct = len([True for c in self.table.columns if c[1][0][:3] == "ct-"]) != 0
57         if (self.table.cleanup.function == no_cleanup and
58                 not self.table.fixed_width and
59                 not ct and
60                 (not hasattr(self.table, "do_not_bulk_insert") or not self.table.do_not_bulk_insert)):
61 
62             print ("Inserting data from " + os.path.basename(filename) + "...")
63 
64             columns = self.table.get_insert_columns()
65             statement = """
66 LOAD DATA LOCAL INFILE '""" + filename.replace("\\", "\\\\") + """'
67 INTO TABLE """ + self.table_name() + """
68 FIELDS TERMINATED BY '""" + self.table.delimiter + """'
69 OPTIONALLY ENCLOSED BY '"'
70 LINES TERMINATED BY '\\n'
71 IGNORE """ + str(self.table.header_rows) + """ LINES
72 (""" + columns + ")"
73             try:
74                 self.cursor.execute(mysql_set_autocommit_off)
75                 self.cursor.execute(statement)
76 
77                 self.cursor.execute(mysql_set_autocommit_on)
78             except Exception as e:
79                 self.disconnect()  # If the execute fails the database connection can get hung up
80                 self.cursor.execute(mysql_set_autocommit_on)
81                 return Engine.insert_data_from_file(self, filename)
82         else:
83             return Engine.insert_data_from_file(self, filename)
84 
85     def table_exists(self, dbname, tablename):
86         """Checks to see if the given table exists"""
87         if not hasattr(self, 'existing_table_names'):
88             self.cursor.execute(
89                 "SELECT table_schema, table_name "
90                 "FROM information_schema.tables WHERE table_schema NOT IN "
91                 "('mysql', 'information_schema', 'performance_schema');")
92             self.existing_table_names = set()
93             for schema, table in self.cursor:
94                 self.existing_table_names.add((schema.lower(), table.lower()))
95         return (dbname.lower(), tablename.lower()) in self.existing_table_names
96 
97     def set_engine_encoding(self):
98         """Set MySQL database encoding to match data encoding
99 
100            Please update the encoding lookup table if the required encoding is not present.
101         """
102         encoding = ENCODING.lower()
103         if self.script.encoding:
104             encoding = self.script.encoding.lower()
105         encoding_lookup = {'iso-8859-1': 'latin1', 'latin-1': 'latin1', 'utf-8': 'utf8'}
106         db_encoding = encoding_lookup.get(encoding)
107         self.execute("SET NAMES '{0}';".format(db_encoding))
108 
109     def get_connection(self):
110         """Gets the db connection."""
111         args = {'host': self.opts['host'],
112                 'port': int(self.opts['port']),
113                 'user': self.opts['user'],
114                 'passwd': self.opts['password']}
115         import pymysql as dbapi
116         import pymysql.constants.CLIENT as client
117         args['client_flag'] = client.LOCAL_FILES
118         self.get_input()
119         return dbapi.connect(**args)
120
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/retriever/engines/mysql.py b/retriever/engines/mysql.py
--- a/retriever/engines/mysql.py
+++ b/retriever/engines/mysql.py
@@ -116,4 +116,4 @@
         import pymysql.constants.CLIENT as client
         args['client_flag'] = client.LOCAL_FILES
         self.get_input()
-        return dbapi.connect(**args)
+        return dbapi.connect(read_default_file='~/.my.cnf', **args)

{"golden_diff": "diff --git a/retriever/engines/mysql.py b/retriever/engines/mysql.py\n--- a/retriever/engines/mysql.py\n+++ b/retriever/engines/mysql.py\n@@ -116,4 +116,4 @@\n         import pymysql.constants.CLIENT as client\n         args['client_flag'] = client.LOCAL_FILES\n         self.get_input()\n-        return dbapi.connect(**args)\n+        return dbapi.connect(read_default_file='~/.my.cnf', **args)\n", "issue": "Check MySQL and Postgres credential files\nIn addition to allowing users to directly provide their MySQL and PostgreSQL credentials, it should also be possible for them to store these credentials in the usual places.\n\nWe should check information given by the user to the retriever first, and then fall back on the configuration files for usernames and passwords if they are not provided.\n\nFor PostgreSQL this is `~/.pgpass` with the format:\n\n```\nhostname:port:database:username:password \n```\n\nSee: https://wiki.postgresql.org/wiki/Pgpass. `*`s can be used in place of any of the `:` separated values.\n\nFor MySQL this is `~/.my.cnf` with the format:\n\n```\n[client]\nuser = root\npassword = yourpassword\n```\n\nSee: https://dev.mysql.com/doc/refman/5.5/en/option-files.html. `.my.cnf` can contain a lot of additional configuration information so we'll need to look explicitly for `user =` and `password =`.\n\n", "before_files": [{"content": "from __future__ import print_function\nfrom builtins import str\nimport os\nfrom retriever.lib.models import Engine, no_cleanup\nfrom retriever import ENCODING\n\n\nclass engine(Engine):\n    \"\"\"Engine instance for MySQL.\"\"\"\n    name = \"MySQL\"\n    abbreviation = \"mysql\"\n    datatypes = {\n        \"auto\": \"INT(5) NOT NULL AUTO_INCREMENT\",\n        \"int\": \"INT\",\n        \"bigint\": \"BIGINT\",\n        \"double\": \"DOUBLE\",\n        \"decimal\": \"DECIMAL\",\n        \"char\": (\"TEXT\", \"VARCHAR\"),\n        \"bool\": \"BOOL\",\n    }\n    max_int = 4294967295\n    placeholder = \"%s\"\n    required_opts = [(\"user\",\n                      \"Enter your MySQL username\",\n                      \"root\"),\n                     (\"password\",\n                      \"Enter your password\",\n                      \"\"),\n                     (\"host\",\n                      \"Enter your MySQL host\",\n                      \"localhost\"),\n                     (\"port\",\n                      \"Enter your MySQL port\",\n                      3306),\n                     (\"database_name\",\n                      \"Format of database name\",\n                      \"{db}\"),\n                     (\"table_name\",\n                      \"Format of table name\",\n                      \"{db}.{table}\"),\n                     ]\n\n    def create_db_statement(self):\n        \"\"\"Returns a SQL statement to create a database.\"\"\"\n        createstatement = \"CREATE DATABASE IF NOT EXISTS \" + self.database_name()\n        return createstatement\n\n    def insert_data_from_file(self, filename):\n        \"\"\"Calls MySQL \"LOAD DATA LOCAL INFILE\" statement to perform a bulk\n        insert.\"\"\"\n\n        mysql_set_autocommit_off = \"\"\"SET autocommit=0; SET UNIQUE_CHECKS=0; SET FOREIGN_KEY_CHECKS=0; SET sql_log_bin=0;\"\"\"\n        mysql_set_autocommit_on = \"\"\"SET GLOBAL innodb_flush_log_at_trx_commit=1; COMMIT; SET autocommit=1; SET unique_checks=1; SET foreign_key_checks=1;\"\"\"\n        \n        self.get_cursor()\n        ct = len([True for c in self.table.columns if c[1][0][:3] == \"ct-\"]) != 0\n        if (self.table.cleanup.function == no_cleanup and\n                not self.table.fixed_width and\n                not ct and\n                (not hasattr(self.table, \"do_not_bulk_insert\") or not self.table.do_not_bulk_insert)):\n\n            print (\"Inserting data from \" + os.path.basename(filename) + \"...\")\n\n            columns = self.table.get_insert_columns()\n            statement = \"\"\"\nLOAD DATA LOCAL INFILE '\"\"\" + filename.replace(\"\\\\\", \"\\\\\\\\\") + \"\"\"'\nINTO TABLE \"\"\" + self.table_name() + \"\"\"\nFIELDS TERMINATED BY '\"\"\" + self.table.delimiter + \"\"\"'\nOPTIONALLY ENCLOSED BY '\"'\nLINES TERMINATED BY '\\\\n'\nIGNORE \"\"\" + str(self.table.header_rows) + \"\"\" LINES\n(\"\"\" + columns + \")\"\n            try:\n                self.cursor.execute(mysql_set_autocommit_off)\n                self.cursor.execute(statement)\n\n                self.cursor.execute(mysql_set_autocommit_on)\n            except Exception as e:\n                self.disconnect()  # If the execute fails the database connection can get hung up\n                self.cursor.execute(mysql_set_autocommit_on)\n                return Engine.insert_data_from_file(self, filename)\n        else:\n            return Engine.insert_data_from_file(self, filename)\n\n    def table_exists(self, dbname, tablename):\n        \"\"\"Checks to see if the given table exists\"\"\"\n        if not hasattr(self, 'existing_table_names'):\n            self.cursor.execute(\n                \"SELECT table_schema, table_name \"\n                \"FROM information_schema.tables WHERE table_schema NOT IN \"\n                \"('mysql', 'information_schema', 'performance_schema');\")\n            self.existing_table_names = set()\n            for schema, table in self.cursor:\n                self.existing_table_names.add((schema.lower(), table.lower()))\n        return (dbname.lower(), tablename.lower()) in self.existing_table_names\n\n    def set_engine_encoding(self):\n        \"\"\"Set MySQL database encoding to match data encoding\n\n           Please update the encoding lookup table if the required encoding is not present.\n        \"\"\"\n        encoding = ENCODING.lower()\n        if self.script.encoding:\n            encoding = self.script.encoding.lower()\n        encoding_lookup = {'iso-8859-1': 'latin1', 'latin-1': 'latin1', 'utf-8': 'utf8'}\n        db_encoding = encoding_lookup.get(encoding)\n        self.execute(\"SET NAMES '{0}';\".format(db_encoding))\n\n    def get_connection(self):\n        \"\"\"Gets the db connection.\"\"\"\n        args = {'host': self.opts['host'],\n                'port': int(self.opts['port']),\n                'user': self.opts['user'],\n                'passwd': self.opts['password']}\n        import pymysql as dbapi\n        import pymysql.constants.CLIENT as client\n        args['client_flag'] = client.LOCAL_FILES\n        self.get_input()\n        return dbapi.connect(**args)\n", "path": "retriever/engines/mysql.py"}], "after_files": [{"content": "from __future__ import print_function\nfrom builtins import str\nimport os\nfrom retriever.lib.models import Engine, no_cleanup\nfrom retriever import ENCODING\n\n\nclass engine(Engine):\n    \"\"\"Engine instance for MySQL.\"\"\"\n    name = \"MySQL\"\n    abbreviation = \"mysql\"\n    datatypes = {\n        \"auto\": \"INT(5) NOT NULL AUTO_INCREMENT\",\n        \"int\": \"INT\",\n        \"bigint\": \"BIGINT\",\n        \"double\": \"DOUBLE\",\n        \"decimal\": \"DECIMAL\",\n        \"char\": (\"TEXT\", \"VARCHAR\"),\n        \"bool\": \"BOOL\",\n    }\n    max_int = 4294967295\n    placeholder = \"%s\"\n    required_opts = [(\"user\",\n                      \"Enter your MySQL username\",\n                      \"root\"),\n                     (\"password\",\n                      \"Enter your password\",\n                      \"\"),\n                     (\"host\",\n                      \"Enter your MySQL host\",\n                      \"localhost\"),\n                     (\"port\",\n                      \"Enter your MySQL port\",\n                      3306),\n                     (\"database_name\",\n                      \"Format of database name\",\n                      \"{db}\"),\n                     (\"table_name\",\n                      \"Format of table name\",\n                      \"{db}.{table}\"),\n                     ]\n\n    def create_db_statement(self):\n        \"\"\"Returns a SQL statement to create a database.\"\"\"\n        createstatement = \"CREATE DATABASE IF NOT EXISTS \" + self.database_name()\n        return createstatement\n\n    def insert_data_from_file(self, filename):\n        \"\"\"Calls MySQL \"LOAD DATA LOCAL INFILE\" statement to perform a bulk\n        insert.\"\"\"\n\n        mysql_set_autocommit_off = \"\"\"SET autocommit=0; SET UNIQUE_CHECKS=0; SET FOREIGN_KEY_CHECKS=0; SET sql_log_bin=0;\"\"\"\n        mysql_set_autocommit_on = \"\"\"SET GLOBAL innodb_flush_log_at_trx_commit=1; COMMIT; SET autocommit=1; SET unique_checks=1; SET foreign_key_checks=1;\"\"\"\n        \n        self.get_cursor()\n        ct = len([True for c in self.table.columns if c[1][0][:3] == \"ct-\"]) != 0\n        if (self.table.cleanup.function == no_cleanup and\n                not self.table.fixed_width and\n                not ct and\n                (not hasattr(self.table, \"do_not_bulk_insert\") or not self.table.do_not_bulk_insert)):\n\n            print (\"Inserting data from \" + os.path.basename(filename) + \"...\")\n\n            columns = self.table.get_insert_columns()\n            statement = \"\"\"\nLOAD DATA LOCAL INFILE '\"\"\" + filename.replace(\"\\\\\", \"\\\\\\\\\") + \"\"\"'\nINTO TABLE \"\"\" + self.table_name() + \"\"\"\nFIELDS TERMINATED BY '\"\"\" + self.table.delimiter + \"\"\"'\nOPTIONALLY ENCLOSED BY '\"'\nLINES TERMINATED BY '\\\\n'\nIGNORE \"\"\" + str(self.table.header_rows) + \"\"\" LINES\n(\"\"\" + columns + \")\"\n            try:\n                self.cursor.execute(mysql_set_autocommit_off)\n                self.cursor.execute(statement)\n\n                self.cursor.execute(mysql_set_autocommit_on)\n            except Exception as e:\n                self.disconnect()  # If the execute fails the database connection can get hung up\n                self.cursor.execute(mysql_set_autocommit_on)\n                return Engine.insert_data_from_file(self, filename)\n        else:\n            return Engine.insert_data_from_file(self, filename)\n\n    def table_exists(self, dbname, tablename):\n        \"\"\"Checks to see if the given table exists\"\"\"\n        if not hasattr(self, 'existing_table_names'):\n            self.cursor.execute(\n                \"SELECT table_schema, table_name \"\n                \"FROM information_schema.tables WHERE table_schema NOT IN \"\n                \"('mysql', 'information_schema', 'performance_schema');\")\n            self.existing_table_names = set()\n            for schema, table in self.cursor:\n                self.existing_table_names.add((schema.lower(), table.lower()))\n        return (dbname.lower(), tablename.lower()) in self.existing_table_names\n\n    def set_engine_encoding(self):\n        \"\"\"Set MySQL database encoding to match data encoding\n\n           Please update the encoding lookup table if the required encoding is not present.\n        \"\"\"\n        encoding = ENCODING.lower()\n        if self.script.encoding:\n            encoding = self.script.encoding.lower()\n        encoding_lookup = {'iso-8859-1': 'latin1', 'latin-1': 'latin1', 'utf-8': 'utf8'}\n        db_encoding = encoding_lookup.get(encoding)\n        self.execute(\"SET NAMES '{0}';\".format(db_encoding))\n\n    def get_connection(self):\n        \"\"\"Gets the db connection.\"\"\"\n        args = {'host': self.opts['host'],\n                'port': int(self.opts['port']),\n                'user': self.opts['user'],\n                'passwd': self.opts['password']}\n        import pymysql as dbapi\n        import pymysql.constants.CLIENT as client\n        args['client_flag'] = client.LOCAL_FILES\n        self.get_input()\n        return dbapi.connect(read_default_file='~/.my.cnf', **args)\n", "path": "retriever/engines/mysql.py"}]}