Vapor 链接 MySQL 8 Using 'caching_sha2_password' auth plugin (default in MySQL >= 8.0.4) over an in...

Here are some possible causes: 
- Using 'caching_sha2_password' auth plugin (default in MySQL >= 8.0.4) over an insecure (no SSL) connection.

These suggestions could address the issue: 
- Use a secure MySQLTransportConfig option in your MySQLDatabaseConfig.
- Use a MySQL auth plugin that does not require full authentication (like 'mysql_native_password').
- Use MySQL < 8.0.4.

Vapor 提供给我们三种解决方式:

Vapor 默认为明文验证,但是 MySQL 8 之后就采取 sha2 加密验证。

1. 更改传输验证方式

/// Configure a MySQL database
    let mysql = try MySQLDatabase(config: MySQLDatabaseConfig(
            hostname: "127.0.0.1",
            port: 3306,
            username: "root",
            password: nil,
            database: "blog",
            capabilities: .default,
            characterSet: .utf8mb4_unicode_ci,
            transport: .unverifiedTLS  // 此处原为 cleartext,即明文
    ))

2. 把 MySQL 的验证方式改为 mysql_native_password

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; 

3. 使用旧的 MySQL,此方法略过

你可能感兴趣的:(Vapor 链接 MySQL 8 Using 'caching_sha2_password' auth plugin (default in MySQL >= 8.0.4) over an in...)