PlanetScaleDb Prisma Setup - server does not allow insecure connections, client must use SSL/TLS

10.4k Views Asked by At

I am starting a brand new PlanetScale backed project, with a Prisma setup. I followed the instruction on this official documentation (aside from changing the name of the database) and after locally proxying into the database, I found myself unable to run npx prisma db push command, getting the following error:

server does not allow insecure connections, client must use SSL/TLS

I am very new to database set ups, and prior to this never had an idea I would need to configure any of these connections as I thought they were dealt with as part of what database set-up I was using.

I know that mySql, what I am using through Prisma, needs either an SSL or TLS before it will perform any interactions on a database, but I have yet to find any way to set this up for my environment.

I have seen references to adding ?tls={true} to the end of my DATABASE_URL but that did nothing. Furthermore, given that the provided DATABASE_URL was provided by PlanetScale as

DATABASE_URL='mysql://un5pbmobnc73muwvbo77:************@us-east.connect.psdb.cloud/*******?ssl={"rejectUnauthorized":true}'

I attempted to change {"rejectUnauthorized":true} to {"rejectUnauthorized":false}. This also changed nothing. More elaborate solutions involving objects are the parameters resulted in my database not being found altogether.

I know SSL is deprecated and I should not use it, but not only do I not know how to properly add TLS to my mySQL, but as you may have already determined, I'm finding myself somewhat unable to fully grasp the concept of its implementation at all.

2

There are 2 best solutions below

3
On

Replace ?ssl={"rejectUnauthorized":true} with ?sslaccept=strict. Below is an example.

DATABASE_URL="mysql://xxxx:[email protected]/zzzz?sslaccept=strict"

Details are written below.

https://www.prisma.io/docs/concepts/database-connectors/mysql#arguments

Good luck!

0
On

For a Laravel application, your ".env" file should look like this:

  • DB_CONNECTION=mysql
  • DB_HOST=XXXX
  • DB_PORT=XXXX
  • DB_DATABASE=XXXX
  • DB_USERNAME=XXXX
  • DB_PASSWORD=XXXX
  • MYSQL_ATTR_SSL_CA=XXXX

NB: you can get these credentials from your Planetscale account by following the steps below:

  1. Click on the database you wish to get the credentials.
  2. Click on the "Overview" menu option.
  3. Click on the "Get connection strings" in the bottom right corner.
  4. From the "Connect with" dropdown options, select "Laravel".
  5. Copy and paste the credentials from the selected option in your ".env" file.
  6. Run the "php artisan optimize:clear" command and you are good to go.

Congratulations!