Skip to content

Commit 3364c44

Browse files
committed
Prefer the faster localhost DB connection, when appropriate.
If the user specifies a DBHostName of 127.0.0.1, but is using standard MySQL port (3306), use a localhost connection, which will use a Unix socket connection on *nix or shared memory connection on Windows. If any user was relying on our previous assumption that specifying a non-zero DBPort implied you wanted to use a TCP/IP connection, they may need to specify an appropriate grant allowing access to MySQL via localhost for the mythtv database user. If, for some strange reason, a user wants to use the slower TCP/IP connection to a local MySQL server, they will need to specify a routable IP address for DBHostName in their mysql.txt/config.xml. This should fix the issue Robert K found after 859ad36, and prevent us from using a slow TCP/IP connection when there's no good reason.
1 parent 5a5d47e commit 3364c44

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mythtv/libs/libmythbase/mythdbcon.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ bool MSqlDatabase::OpenDatabase(bool skipdb)
123123
if (m_dbparms.dbPort)
124124
m_db.setPort(m_dbparms.dbPort);
125125

126-
if (m_dbparms.dbPort && m_dbparms.dbHostName == "localhost")
127-
m_db.setHostName("127.0.0.1");
126+
// Prefer using the faster localhost connection if using standard
127+
// ports, even if the user specified a DBHostName of 127.0.0.1. This
128+
// will cause MySQL to use a Unix socket (on *nix) or shared memory (on
129+
// Windows) connection.
130+
if ((m_dbparms.dbPort == 0 || m_dbparms.dbPort == 3306) &&
131+
m_dbparms.dbHostName == "127.0.0.1")
132+
m_db.setHostName("localhost");
128133

129134
connected = m_db.open();
130135

0 commit comments

Comments
 (0)