Discord Node JS, cannot connect to mySQL database (installed in package the mySQL driver) please help!?

const mysql = require("mysql");
var con = mysql.createConnection({
  host: "localhost",
  user: "root",
  password: "1234",
  database: "sadb"
});

con.connect(err => {
  if (err) throw err;
  console.log("mySQL connection successful.");
  
});

What’s wrong here???
I’m trying to connect and this is the error:

if (err) throw err;
^

Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
--------------------
at Protocol._enqueue (/rbd/pnpm-volume/ac7de4cc-7438-48ed-90b5-3e4286f3a159/node_modules/.registry.npmjs.org/mysql/2.16.0/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/rbd/pnpm-volume/ac7de4cc-7438-48ed-90b5-3e4286f3a159/node_modules/.registry.npmjs.org/mysql/2.16.0/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/rbd/pnpm-volume/ac7de4cc-7438-48ed-90b5-3e4286f3a159/node_modules/.registry.npmjs.org/mysql/2.16.0/node_modules/mysql/lib/Connection.js:118:18)
Jump to

at Object.<anonymous> (/app/main.js:48:5)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)

Why???


MOD EDIT: formatting

Hey @dRsaf3, welcome to the Glitch Forums!

You won’t be able to host a MySQL database in this fashion on Glitch - we only open a single port, so you won’t be able to connect to :3306 like you’ve tried in your code.

If you want to use MySQL you’ll have to host it with some 3rd party database hosting.

Sorry for the bother!

What can I use instead of mySQL then? What do you recommend?

Thanks :slight_smile:

Hey there! Check out this team on Glitch for some projects to learn from: https://glitch.com/@storage

Some of my favorites are low-db (a JSON file you can treat as a DB), sqlite3-db (a SQL db that’s similar to MySQL that Glitch can support), and mongodb if you want to try out a No-SQL database. You can even get silly and use Google Sheets or Airtable (both spreadsheet software) as your database!