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,此方法略过

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容