Trouble with Prisma MySQL connection string when using socket connection method

Just going through Mosh’s Next.JS Issue Tracker course and having utter frustration with the DATABASE_URL string for Prisma to use in .env file.

I installed MySQL on my Ubuntu WSL installation on Windows and also ran the mysql_secure_installation. Oddly, I was not asked to provide a password and the sudo apt install mysql-server method of installing has defaulted to using auth-socket instead of a password, so in this case Prisma says the connection string if using sockets and not password should look like this:

mysql://USER:POST@localhost/database?socket=/var/run/mysql/

I change USER to root, database to issue_tracker and the socket path to /var/run/mysqld/ which is the path as set in my Ubuntu install.

This results in:

mysql://root:POST@localhost/issue_tracker?socket=/var/run/mysqld/

Running a migration with this results in the following error:

Error: P1001: Can't reach database server at `localhost`:`3306`

Please make sure your database server is running at `localhost`:`3306`.

The annoying thing is I can easily connect to mysql from the terminal command line using sudo mysql and check the status and default users and databases in there. I just cannot get the Prisma connection string to work.

I suspect it has to be something to do with the word POST, as shown in the Prisma docs example. What the hell are you supposed to replace that with? Or do you leave it as POST

At this stage I might just drop MySQL and use PostgresSQL which I’ve never had issues connecting with before (though not from Prisma).

Any advice will be appreciated.

I solved things by the following method discussed on Stack Overflow link below:

Prisma URL string for MySQL connection via sockets - Stack Overflow

Another tip when editing the connection string for DATABASE_URL env variable is do not use wildcard symbols such as *, ! or ?. Also don’t use @.

Additionally, any symbol you use should be percent encoded instead of entering it literally. So, is say you have a password like $mySecretPass0rd using the $ symbol, your DATABASE_URL string should look like this:

DATABASE_URL=mysql://root:%24mySecretPass0rd@localhost:3306/issue_tracker

The %24 is the percent encoded number for $. You can use the percent encoder tool in the link below to find the number for your chosen password symbol.

Online Percent Encoder Tool