skip to Main Content

I am trying to connect to the mysql database from my express server in cpanel (the databse and server are both in cpanel) , I already added a user, and I’m trying to connect via localhost but this ain’t working
below is the code:

const db = mysql.createPool({
  host: "localhost",
  user: \user\,
  password: \password\,
  database: "ts34mpr_SCMP",
  dateStrings: true,
});

The request isn’t reaching the databse although I added the user with all privileges and the user with password are 100% correct.
Any help please?
Thank you!

2

Answers


  1. Try this:

    const mysql = require('mysql');
    const connection = mysql.createConnection({
        host: 'localhost',
        user: 'root',
        password: '',
        database: 'cpanel'
    });
    
    Login or Signup to reply.
  2. You can just put % to allow all (https://forums.cpanel.net/threads/allow-any-host-to-connect-to-mysql-remotely.189131/post-774871), or you can put the ip address where you will get the error like Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'db_name'@'491.25.***.***' (using password: YES)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search