I found this issue while setting up a new Vapor 4 project on macOS, with MySQL 8.0.17
Being both Vapor and MySQL running on localhost, there is no SSL certificate involved. However, seems like mysql-nio tries to connect via SSL, and fails to verify the "missing" certificate.
To solve this issue, while working on localhost or without SSL connection, Vapor's MySQL client can be configured to not do certificate verification, as follows:
.mysql(hostname: host, ..., tlsConfiguration: .forClient(certificateVerification: .none))
Here is a full code example with a bare-bone project setup:
import Vapor
import Fluent
import FluentMySQLDriver
// configures your application
public func configure(_ app: Application) throws {
// uncomment to serve files from /Public folder
// app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
configureDatabase(app: app)
// register routes
try routes(app)
}
func configureDatabase(app: Application) {
let host = Environment.get("DB_HOST") ?? ""
let port = Environment.get("DB_PORT").flatMap(Int.init) ?? 3306
let user = Environment.get("DB_USER") ?? ""
let pass = Environment.get("DB_PASS") ?? ""
let name = Environment.get("DB_NAME") ?? ""
app.databases.use(.mysql(hostname: host, port: port, username: user, password: pass, database: name, tlsConfiguration: .forClient(certificateVerification: .none)), as: .mysql)
}