代码之家  ›  专栏  ›  技术社区  ›  Orlando

使用Unix套接字的FluentMySQL连接

  •  9
  • Orlando  · 技术社区  · 8 年前

    我在跟踪 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数据库。

    我将能够在生产环境下为应用程序提供的只是数据库名称、用户名、密码和套接字路径,这些都将以表单的形式提供 /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

    谢谢你的帮助。

    0 回复  |  直到 8 年前