-1

I'm using Node and MySQL2 import mysql2 from 'mysql2'

Following successfully creates connection:

const connection = mysql2.createConnection({
        host: 'localhost',
        user: 'root',
        password: 'My@Password',
        database: 'MyDB',
    })

But using the URI format with same attributes throws Access denied for user 'root'@'localhost' (using password: YES)

const connection = mysql2.createConnection(
        'mysql://root:My@Password@localhost:3306/MyDB'
    )

What is the mistake with URI format?

[UPDATE] I've tried to encode the @, but it still doesn't works

'mysql://root:My%40Password@localhost:3306/MyDB' 

Is there a method in MySQL library that returns the URI? I can create successful connection using the first approach and see what URI it actually generates.

helloworld
  • 2,179
  • 3
  • 24
  • 39

1 Answers1

0

We cannot use special characters like '@', ':', '/', in url and you are using '@' in password
Try updating password , that mean without '@' or you need to properly encode the password using the encodeURIComponent function in JavaScript

Saurabh
  • 76
  • 5