prisma: Error 28000(9002): SSL Connection is required even when database does not require

Bug description

When a try to introspect a mysql database at azure i receive an error:

Error: Error in connector: Error querying the database: Error querying the database: Error querying the database: Server error: `ERROR 28000 (9002): SSL connection is required. Please specify SSL options and retry. ’

Even when my database has no SSL required. I dont know if it’s because my database is at Azure or my username is something like ‘134@server-221’

How to reproduce

  1. With DATABASE_URL: “mysql://username@username:password@server.mysql.database.azure.com:3306/database”

  2. Run ‘npx prisma introspect’

  3. See error below: Error: Error in connector: Error querying the database: Error querying the database: Error querying the database: Server error: `ERROR 28000 (9002): SSL connection is required. Please specify SSL options and retry. ’

Expected behavior

Generate Entities from the database.

Prisma information

“mysql://username@username:password@server.mysql.database.azure.com:3306/database”

Environment & setup

  • OS: [Mac OS, Windows]
  • Database: [MySQL]
  • Prisma version: 2.0.0-beta.6
  • Node.js version: v13.13.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

ref)https://docs.microsoft.com/azure/mysql/concepts-ssl-connection-security

In some cases, applications require a local certificate file generated from a trusted Certificate Authority (CA) certificate file to connect securely. Currently customers can only use the predefined certificate to connect to an Azure Database for MySQL server which is located at https://www.digicert.com/CACerts/BaltimoreCyberTrustRoot.crt.pem.

  1. download https://www.digicert.com/CACerts/BaltimoreCyberTrustRoot.crt.pem🔐 and save at /prisma

  2. /prisma/prisma.schema

    generator client {
      provider = "prisma-client-js"
    }
    
    datasource db {
      provider = "mysql"
      url      = env("DATABASE_URL")
    }
    
  3. update /prisma/.env

    DATABASE_URL="mysql://test@test-mysql:mypassword@test.mysql.database.azure.com:3306/testdb?sslmode=require&sslcert=BaltimoreCyberTrustRoot.crt.pem"
    
  4. npx prisma introspect

    Prisma schema loaded from prisma\schema.prisma
    
    Introspecting based on datasource defined in prisma\schema.prisma …
    
    ✔ Introspected 1 model and wrote it into prisma\schema.prisma in 638ms
    
    Run prisma generate to generate Prisma Client.
    
  5. npx prisma generate

  6. 🙆‍♀️🙆‍♂️🙆‍♀️🙆‍♂️🙆‍♀️🙆‍♂️

I faced the same issue and the cert unfortunately didn’t work for me 🤷 Instead I used ?sslaccept=accept_invalid_certs and worked without the cert

@handelcamilo The error is coming the database driver. Can you please make sure that you can connect to your database without ssl from a database GUI or from another driver.