使用 Unix Socket 的 FluentMySQL 连接

FluentMySQL connection using Unix Socket

我正在按照 Getting started section for the MySQL package on the Vapor Documentation 进行操作,我能够逐步进行操作,因此,我已经使用自定义数据库成功建立了与 MySQL 数据库的连接像这样的凭据:

/// Register providers first
try services.register(FluentMySQLProvider())

// MySQL database
let mySQLConfig = MySQLDatabaseConfig(hostname: "localhost",
                                      port: 3306,
                                      username: "root",
                                      password: "thisismyrootpassword",
                                      database: "lol_database",
                                      capabilities: .default,
                                      characterSet: MySQLCharacterSet.utf8_general_ci,
                                      transport: MySQLTransportConfig.cleartext)

services.register(mySQLConfig)

Based on the MySQLDatabaseConfig object's documentation 我无法找到是否可以连接到基于 Unix 套接字配置的 MySQL 数据库。

我可以在生产环境下为应用程序提供的只是数据库名称、用户名、密码和 Socket 路径,其格式为 /cloudsql/project1:us-central1:instance1

为了获得更多参考,我正在尝试做的是根据本教程从 Google Cloud App Engine 灵活环境连接到 SQL 数据库:https://cloud.google.com/appengine/docs/flexible/nodejs/using-cloud-sql#setting_up_your_local_environment 环境当然,Vapor 仍然是数据库客户端与数据库服务器建立连接的唯一方法。

感谢您的帮助。

Times have changed 现在有一个 unix​Domain​Socket​Path 可以用来代替 hostname/port.