0

So i have been trying to connect to a MySQL database from my electron app:

    <script>
    var mysql = require('mysql');
    var connection = mysql.createConnection({
        host     : '*********',
        user     : '******',
        password : '******',
        port     : '******',
        debug    : 'true'
    });
    console.log('trying to connect to DB')
    connection.connect(function(err) {
        if (err) {
            console.error('error connecting: ' + err.stack);
            return;
        }    
        console.log('connected as id ' + connection.threadId);
        });
    connection.end()
</script>

My code gets stuck on connection.connect and after about 1 min it give me:

    error connecting: Error: read ECONNRESET
      at exports._errnoException (util.js:1024:11)
      at TCP.onread (net.js:610:25)

I have no idea what to do, anyone have any ideas?

Chsir17
  • 629
  • 1
  • 7
  • 18

1 Answers1

0

The chances are that your mssql instance on your lan is not configured to allow connections to anything but your local machine, i.e the machine that mssql is installed.

To allow connections from your LAN you need to edit the following:

edit my.conf and find the bind-address parameter in the [mysqld] section, this will probably be set to localhost or 127.0.0.1, you can either change this to the ip of the machine you want to connect to the database, or use a wildcard and allow your whole local range, e.g 192.168.0.* or 0.0.0.0

You will need to grant access to the database you are trying to connect to

GRANT ALL ON <local database name>.* TO <user>@<iptryingtoconnectfrom> IDENTIFIED BY '<database user password>';

Restart the mysql service and you should be good to go.

dave
  • 1,410
  • 1
  • 16
  • 42