vapor 链接MySQL失败

configure.swift

    // === mysql ===
    // 首先注册数据库
    try services.register(FluentMySQLProvider())

    // Configure a MySQL database
    let mysql = MySQLDatabase(config: MySQLDatabaseConfig(hostname: "", port: 3306, username: "root", password: "***", database: "vapor", capabilities: .default, characterSet: .utf8mb4_unicode_ci, transport: .unverifiedTLS))

    // Register the configured SQLite database to the database config.
    var databases = DatabasesConfig()
    databases.add(database: mysql, as: .mysql)
    services.register(databases)

运行后报错

[ INFO ] Migrating 'mysql' database (/Users/roo/Roo/Vapor/NewProject/.build/checkouts/fluent/Sources/Fluent/Migration/MigrationConfig.swift:69)
Fatal error: Error raised at top level: ⚠️ MySQL Error: Unknown database 'vapor'
- id: MySQLError.server (1049)

File: /Users/roo/Roo/Vapor/NewProject/.build/checkouts/mysql/Sources/MySQL/Connection/MySQLConnectionHandler.swift
 - func: handlePacket(ctx:packet:)
 - line: 99
 - column: 42
: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1001.8.63.13/swift/stdlib/public/core/ErrorType.swift, line 200
2019-08-13 20:22:07.177378+0800 Run[45878:534880] Fatal error: Error raised at top level: ⚠️ MySQL Error: Unknown database 'vapor'
- id: MySQLError.server (1049)

File: /Users/roo/Roo/Vapor/NewProject/.build/checkouts/mysql/Sources/MySQL/Connection/MySQLConnectionHandler.swift
 - func: handlePacket(ctx:packet:)
 - line: 99
 - column: 42
: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1001.8.63.13/swift/stdlib/public/core/ErrorType.swift, line 200
(lldb) 

之所以会出现这种问题是因为没有 vapor数据库

新建vapor 数据库解决问题

 

上一篇:SpringApplication到底run了什么(上)


下一篇:05 flume将数据导入到Hive