Sign in to follow this  
Avensio

NodeJS Mysql connection impossible since V0.3.5

Recommended Posts

Hello,

 

My script used to connect to my remote hosted DB fine in V0.3.5. However, since updating to V0.3.6+ I can only connect to my localhost. This is the only code in my packages:


 

var mysql = require('mysql');
console.log('conn');
var conn = mysql.createConnection({
    host: 'MY_REMOTE_IP',
    user: 'MY_REMOTE_USR',
    debug: true,
    password: 'MY_REMOTE_PW',
    database: 'MY_REMOTE_DB',
    supportBigNumbers: true
});
conn.connect(function (err) { console.log('Got connected'); });
conn.query('SELECT * from accounts', function (error, results, fields) {
    if (error) console.log(error);
    console.log('account ', results[0]);
});

The host says the DB is configured fine (host is a Game Server host) and it must be NodeJS or Rage. However when I run the above index.js from terminal I get connection and even the rows in the database.

I see that V0.3.6 had some NodeJS adjustments, security enhancements and V8. 

I've installed the latest NPM, NodeJS and mysql JS package. The host refers me to Rage, mysql JS community refers me to the DB host. What can I do?

 

 

 

 

Share this post


Link to post
Share on other sites

My Server runs with remote mysql just fine.

You have to check your MySQL Server config for:

bind=127.0.0.1

and comment that out or change to 0.0.0.0.

There is no direct connection between Rage MP Server and mysql module, therefore, the problem is somewhere else ...

Edited by DampflokTV
typo

Share this post


Link to post
Share on other sites

Thanks for your reply. I've checked the bind-address property, it is set to '*'. I understand there is no connection between Rage and MySQL. However, the odd thing is that this problem only occurs on V0.3.5+. In which way is that possible without mentioning Rage?

Edited by Avensio

Share this post


Link to post
Share on other sites

I am not sure, if this helps you but I had some issues also with mysql (but I am not using mysql directly but typeorm which uses mysql or mysql2)

Here my foundings:

  • I had for example the issue that mysql2 was absolutly not connection but mysql package itself does. So I suggest to use mysql instead of mysql2 [Ok you do that already but I wanted to clarify that if someone else has this problem] - maybe if mysql not working you cou
  • In case of windows, I had more often random issues (not connecting or if connected queries doesn't get executed)... until I tried to start RageMP Server as admin - it doesn't do that by default
  • Depending on your code: if you call your function in an async function it should not be called in an RageMP Event or something like that... this causes problems - not sure why but I found A LOT of issues with async/await and Promises  - in that case I builded a wrapper function with a 0 seconds timer - this solves all of that problems. AND also some of my mysql issues because typeorm is written async (not sure if that is internally also the case in mysql package - but could be)

// Disclaimer: All that issues are RageMP related :D, without RageMP it's working fine :D I have more such issues already on list but not related to mysql - Why is the Bugtracker not working of RageMP 😢 

I know that these maybe don''t solve your issues but maybe it helps you a bit to find the issue or people that have similar issues like me.

Edited by Geramy92

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.