skip to Main Content

I am acually remaking a wordpress site from scratch with React (for frontend) , Node and express (for backend). There are a lot of post on the current wordpress site database and i want to use the same database and will just use Node and express to create, read, update or delete posts. I see the phpmyadmin panel but there is a big mess (3 database and 20+ tables on each database and a lot of entry on each table) of data and i don’t know where is the real post and what should i do now. I try this code to connect with the database

const mysql = require('mysql');

const connection = mysql.createConnection({
    host: 'localhost',
    user: 'user_name',
    password: 'password',
    database: 'database name'
});

connection.connect((err) => {
    if (err) {
        console.error('Error connecting to the database:', err);
        return;
    }
    console.log('Connected to the database');
});

module.exports = connection;

when i run this code this give me a error

Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'my_user_name'@'localhost' (using password: YES)

i am getting all the connection data(user, password, database, host) from wordpress file manager wp-config.php and now don’t know how to make the backend with node.

Please anyone know what to do next help me to create the backend๐Ÿ™๐Ÿ™๐Ÿ™

2

Answers


  1. Chosen as BEST ANSWER

    I figure it out. You just have to give you're remote host name which you'll find on cpanel and you have to add you're local ip adress to the remote mysql host.


  2. try this approach

    const pool = mysql.createPool({
    connectionLimit : 10,
    host            : 'localhost',
    user            : 'user name',
    password        : 'password',
    database        : 'database name'
    
    })
    
      pool.getConnection((err, connection) => {
        if(err) throw err
        console.log(`connected as id ${connection.threadId}`)
    
        connection.query('SELECT * from users', (err, rows) => {
            connection.release() // return the connection to pool
    
            if(!err) {
                res.send(rows)
            } else {
                console.log(err)
            }
    
        })
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search