Skip to content

Commit d30d54c

Browse files
Optionally load connection arguments from the environment.
1 parent 4050c74 commit d30d54c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

MySQLdb/connections.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
NotSupportedError, ProgrammingError
1212
import _mysql
1313
import re
14+
import os
1415

1516

1617
if not PY2:
@@ -144,7 +145,12 @@ class object, used to create cursors (keyword only)
144145
from MySQLdb.converters import conversions
145146
from weakref import proxy
146147

147-
kwargs2 = kwargs.copy()
148+
# Load values from the environment if provided.
149+
# Anything passed locally overrides the environment.
150+
kwargs2 = {key.split("PY_MYSQL_CONNECT_", 1)[1].lower(): value
151+
for key, value in os.environ.items
152+
if key.startswith("PY_MYSQL_CONNECT_")}
153+
kwargs2.update(kwargs)
148154

149155
if 'database' in kwargs2:
150156
kwargs2['db'] = kwargs2.pop('database')

0 commit comments

Comments
 (0)