Supply MySQL database hostname when using Unix sockets to connect (#7471)

* Supply MySQL database hostname when using Unix sockets to connect

* Pass unix_socket parameter when db_socket is set

* Set db_host to localhost when db_socket is set
This commit is contained in:
ZedTheYeti
2017-10-17 21:55:41 -05:00
committed by Tony Murray
parent 04bb65b762
commit ee5c223669
2 changed files with 5 additions and 8 deletions

View File

@@ -39,7 +39,7 @@ $config['db_port']=$dbport;
$config['db_socket']=$dbsocket;
if (!empty($config['db_socket'])) {
$config['db_host'] = '';
$config['db_host'] = 'localhost';
$config['db_port'] = null;
} else {
$config['db_socket'] = null;

View File

@@ -79,12 +79,9 @@ db_username = config['db_user']
db_password = config['db_pass']
db_port = int(config['db_port'])
if config['db_host'][:5].lower() == 'unix:':
if config['db_socket']:
db_server = config['db_host']
db_port = 0
elif config['db_socket']:
db_server = config['db_socket']
db_port = 0
db_socket = config['db_socket']
else:
db_server = config['db_host']
@@ -93,8 +90,8 @@ db_dbname = config['db_name']
def db_open():
try:
if db_port == 0:
db = MySQLdb.connect(host=db_server, user=db_username, passwd=db_password, db=db_dbname)
if db_socket:
db = MySQLdb.connect(host=db_server, unix_socket=db_socket, user=db_username, passwd=db_password, db=db_dbname)
else:
db = MySQLdb.connect(host=db_server, port=db_port, user=db_username, passwd=db_password, db=db_dbname)
return db