node red - ER_ACCESS_DENIED_NO_PASSWORD_ERROR: Access denied for user ''@'localhost' - Stack Ove

admin2025-04-25  2

I use the @flowfuse dashboard, I wanted to modify the ui-gauge node, so that every time there is an update in my table, it updates my gauge accordingly

I use mysql and @rodrigos/mysql-events for that

However when I launch node red with a gauge node, I have this error: Error: ER_ACCESS_DENIED_NO_PASSWORD_ERROR: Access denied for user ''@'localhost'

I have the impression that it does not take into account my password and my user, here is my code:

module.exports = function (RED) {

    const mysql = require('mysql');
    const MySQLEvents = require('@rodrigogs/mysql-events');
    let connection;
    let instance;

    function GaugeNode(config) {
        RED.nodes.createNode(this, config);
        const node = this;
        
        //gaugeNode code here
        
        //my function 
        const program = async () => {
            if (!instance && !connection) {
                connection = mysql.createConnection({
                    host: 'localhost',
                    user: 'root',
                    password: 'mypwd'
                });

                instance = new MySQLEvents(connection, {
                    serverId: serverId,
                    startAtEnd: true,
                    includeSchema: {
                        'rce': ['compteur']
                    }
                });
                
                await instance.start();
            }
            else{
                instance.removeTrigger({
                    name: 'actualisationJauge',
                    expression: 'rcepteur.value',
                    statement: MySQLEvents.STATEMENTS.UPDATE,
                  });
            }
            
            await instance.start();

            instance.addTrigger({
                name: 'actualisationJauge',
                expression: 'rcepteur.value',
                statement: MySQLEvents.STATEMENTS.UPDATE,
                onEvent: (event) => {
                    event.affectedRows.forEach((row) => {
                        const updatedValue = row.after.value;
                        const msg = { payload: updatedValue }; 
                        node.receive(msg);                        
                    });
                }
            });
          
        };
        program();

        node.on('close', function (removed, done) {
            //...
        });
        

    }
    RED.nodes.registerType('ui-gauge', GaugeNode);

    //here i use an ajax request
            }
        });
    });
};

Knowing that in other of my nodes, I use @rodrigogs/mysql-events and mysql in the same way and I never had this error, while I really copied my way of doing from my nodes that work.

I have already seen forums with this error but I have never managed to understand what is the real solution...

转载请注明原文地址:http://anycun.com/QandA/1745531866a90848.html