File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed
Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -430,13 +430,27 @@ def _connect():
430430 else :
431431 raise e
432432
433+ def _fallback_to_tcp_ip ():
434+ self .echo (
435+ 'Retrying over TCP/IP' , err = True )
436+
437+ # Else fall back to TCP/IP localhost
438+ nonlocal socket , host , port
439+ socket = ""
440+ host = 'localhost'
441+ port = 3306
442+ _connect ()
443+
433444 try :
434445 if (host is None ) and not WIN :
435446 # Try a sensible default socket first (simplifies auth)
436447 # If we get a connection error, try tcp/ip localhost
437448 try :
438449 socket = socket or guess_socket_location ()
439450 _connect ()
451+ except FileNotFoundError :
452+ self .echo ('Failed to find socket file at default locations' )
453+ _fallback_to_tcp_ip ()
440454 except OperationalError as e :
441455 # These are "Can't open socket" and 2x "Can't connect"
442456 if [code for code in (2001 , 2002 , 2003 ) if code == e .args [0 ]]:
@@ -447,14 +461,7 @@ def _connect():
447461 self .echo (
448462 "Failed to connect to local MySQL server through socket '{}':" .format (socket ))
449463 self .echo (str (e ), err = True )
450- self .echo (
451- 'Retrying over TCP/IP' , err = True )
452-
453- # Else fall back to TCP/IP localhost
454- socket = ""
455- host = 'localhost'
456- port = 3306
457- _connect ()
464+ _fallback_to_tcp_ip ()
458465 else :
459466 raise e
460467 else :
Original file line number Diff line number Diff line change @@ -99,7 +99,8 @@ def guess_socket_location():
9999 for directory in socket_dirs :
100100 for r , dirs , files in os .walk (directory , topdown = True ):
101101 for filename in files :
102- if filename .startswith ("mysql" ) and filename .endswith (".socket" ):
102+ name , ext = os .path .splitext (filename )
103+ if name .startswith ("mysql" ) and ext in ('.socket' , '.sock' ):
103104 return os .path .join (r , filename )
104105 dirs [:] = [d for d in dirs if d .startswith ("mysql" )]
105- return ""
106+ raise FileNotFoundError
You can’t perform that action at this time.
0 commit comments