Skip to content

Commit fe836ec

Browse files
authored
Set default mysql port to 3306 (#293)
1 parent 084c2a9 commit fe836ec

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Sources/MySQLKit/MySQLConfiguration.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ public struct MySQLConfiguration {
88
public let password: String
99
public let database: String?
1010
public let tlsConfiguration: TLSConfiguration?
11-
11+
12+
/// IANA-assigned port number for MySQL
13+
/// `UInt16(getservbyname("mysql", "tcp").pointee.s_port).byteSwapped`
14+
public static var ianaPortNumber: Int { 3306 }
15+
1216
internal var _hostname: String?
1317

1418
public init?(url: String) {
@@ -31,9 +35,7 @@ public struct MySQLConfiguration {
3135
guard let hostname = url.host else {
3236
return nil
3337
}
34-
guard let port = url.port else {
35-
return nil
36-
}
38+
let port = url.port ?? Self.ianaPortNumber
3739

3840
let tlsConfiguration: TLSConfiguration?
3941
if url.query == "ssl=false" {
@@ -70,7 +72,7 @@ public struct MySQLConfiguration {
7072

7173
public init(
7274
hostname: String,
73-
port: Int = 3306,
75+
port: Int = Self.ianaPortNumber,
7476
username: String,
7577
password: String,
7678
database: String? = nil,

0 commit comments

Comments
 (0)