Skip to content

Commit

Permalink
connect mariadb via unix_socket
Browse files Browse the repository at this point in the history
  • Loading branch information
imwhatiam committed Feb 20, 2024
1 parent ff58431 commit 7303f11
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ def create_engine_from_conf(config, db='seafevent'):
else:
port = 3306
username = config.get(db_sec, user)
passwd = config.get(db_sec, 'password')
dbname = config.get(db_sec, db_name)
db_url = "mysql+pymysql://%s:%s@%s:%s/%s?charset=utf8" % (username, quote_plus(passwd), host, port, dbname)

if config.has_option(db_sec, 'password'):
passwd = config.get(db_sec, 'password')
db_url = "mysql+pymysql://%s:%s@%s:%s/%s?charset=utf8" % (username, quote_plus(passwd), host, port, dbname)

if config.has_option(db_sec, 'unix_socket'):
unix_socket = config.get(db_sec, 'unix_socket')
db_url = f"mysql+pymysql://{username}:@{host}:{port}/{dbname}?unix_socket={unix_socket}&charset=utf8"

logger.info('[seafevents] database: mysql, name: %s', dbname)

elif backend == 'oracle':
if config.has_option(db_sec, 'host'):
host = config.get(db_sec, 'host').lower()
Expand Down

0 comments on commit 7303f11

Please sign in to comment.