Skip to content

Commit 49d6854

Browse files
author
epriestley
committed
Document how to set a MySQL port
Summary: This already pretty much works, document it explicitly. Test Plan: Moved my MySQL server over to port 3307. Reviewed By: aran Reviewers: jungejason, aran CC: aran Differential Revision: 411
1 parent 112346e commit 49d6854

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

conf/default.conf.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@
7575
// The password to use when connecting to MySQL.
7676
'mysql.pass' => '',
7777

78-
// The MySQL server to connect to.
78+
// The MySQL server to connect to. If you want to connect to a different
79+
// port than the default (which is 3306), specify it in the hostname
80+
// (e.g., db.example.com:1234).
7981
'mysql.host' => 'localhost',
8082

8183
// -- Email ----------------------------------------------------------------- //

scripts/sql/upgrade_schema.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
// Use always the version from the commandline if it is defined
6060
$next_version = isset($options['v']) ? (int)$options['v'] : null;
6161

62+
// TODO: Get this stuff from DatabaseConfigurationProvider?
6263
if ($options['u']) {
6364
$conn_user = $options['u'];
6465
$conn_pass = $options['p'];
@@ -68,6 +69,17 @@
6869
}
6970
$conn_host = PhabricatorEnv::getEnvConfig('mysql.host');
7071

72+
// Split out port information, since the command-line client requires a
73+
// separate flag for the port.
74+
$uri = new PhutilURI('mysql://'.$conn_host);
75+
if ($uri->getPort()) {
76+
$conn_port = $uri->getPort();
77+
$conn_bare_hostname = $uri->getDomain();
78+
} else {
79+
$conn_port = null;
80+
$conn_bare_hostname = $conn_host;
81+
}
82+
7183
$conn = new AphrontMySQLDatabaseConnection(
7284
array(
7385
'user' => $conn_user,
@@ -118,11 +130,17 @@
118130
$short_name = basename($patch['path']);
119131
print "Applying patch {$short_name}...\n";
120132

133+
if ($conn_port) {
134+
$port = '--port='.(int)$conn_port;
135+
} else {
136+
$port = null;
137+
}
138+
121139
list($stdout, $stderr) = execx(
122-
"mysql --user=%s --password=%s --host=%s < %s",
140+
"mysql --user=%s --password=%s --host=%s {$port} < %s",
123141
$conn_user,
124142
$conn_pass,
125-
$conn_host,
143+
$conn_bare_hostname,
126144
$patch['path']);
127145

128146
if ($stderr) {

0 commit comments

Comments
 (0)