Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow connecting to the DB from a specific network interface #529

Merged
merged 2 commits into from
Nov 16, 2016

Conversation

dciabrin
Copy link
Contributor

When connecting via TCP/IP, provide a means to the client to bind the
socket to be created to a specific source address. This is useful
when the client host has multiple network interfaces and a specific
one must be used for database traffic.

Add a new optional "bind" argument to class Connection, to specify the
interface from which to connect to the DB. Argument can be a hostname
or an IP address.

@zzzeek
Copy link
Contributor

zzzeek commented Nov 15, 2016

just a note we are imitating MySQL's own API here, which should also be supported in mysqlclient: MYSQL_OPT_BIND at http://dev.mysql.com/doc/refman/5.7/en/mysql-options.html

@@ -534,7 +534,8 @@ def __init__(self, host=None, user=None, password="",
compress=None, named_pipe=None, no_delay=None,
autocommit=False, db=None, passwd=None, local_infile=False,
max_allowed_packet=16*1024*1024, defer_connect=False,
auth_plugin_map={}, read_timeout=None, write_timeout=None):
auth_plugin_map={}, read_timeout=None, write_timeout=None,
bind=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer bind_address rather than bind. (Same to option name, translated '-' with '_')

@@ -640,6 +645,9 @@ def _config(key, arg):
self.password = password or ""
self.db = database
self.unix_socket = unix_socket
if bind is not None and _py_version == (2, 6):
raise NotImplementedError("bind before connect is not supported in Python 2.6")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 2.6 is not supported anymore. So this check is not required.

@methane methane merged commit 755dfdc into PyMySQL:master Nov 16, 2016
@methane
Copy link
Member

methane commented Nov 16, 2016

thanks

@dciabrin dciabrin deleted the bind-src branch November 16, 2016 13:12
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants