MySQL in NodeJS (Not working?)


#1

Okay so, i got my website from 000webhost with a MySQL Database, but like… I’m trying to connect it with it but it seems like the API is not working for some reason?

Name of the node app: “mysqltesting
Where the stuff is located: “Commands/createvalues.js

I keep getting errors like things are undefined, which should work with the MySQL API


#2

Found a solution, the problem was that it was on “localhost” cause i’m using a free 000webhost account, i’d need to pay to make it external.

Now i kinda got another question, is there a possibility to create a MySQL Database within glitch? and is this secure?


#3

Hello, @Jethrootje, MySQL is installed in the project container so it’s available but you’ll need to do some custom configuration to get it running. https://glitch.com/~lamp-poc is a project that handles all that configuration that you could remix from. Your MySQL instance won’t be available externally, but you can use it from within your project. From that perspective, it’s more secure then MySQL instances that are accessible over the internet.


#4

Would it be possible to use the MySQL database in the website part of the Node App too?

Like… you have a place for your discord bot, and for your webpage, are you able to use the same database for both?


#5

uh i look at that project you told me to look at, but i get confused, thats not a Node App… Is there any project of how to do it for a Node App?


#6

and is there like a phpMyAdmin for this kind of Database?


#7

If you have your bot and your site in two different projects that won’t work - the MySQL database will only be available on the same project where it’s running.

That said, there’s no reason you can’t have a bot and a website about a bot in the same project and that seems like it’s pretty common. If you arranged things that way then both the bot and the site would have access to the database.

You’re correct, that example isn’t a Node project. What you’d need to do would be to combine the pieces of the lamp-poc project that start the mysql process with the parts of a standard Node project that start the node process running. I don’t know of any examples off the top of my head, but if I come across anything I’ll post it here. I also don’t know of any projects that use phpMyAdmin or similar tools.

Depending on your storage needs something from https://glitch.com/@storage might be more suitable and easier to integrate with.


#8

Is there any way of getting support with setting up the MySQL Database for my Node App? Cause i wouldn’t actually know what to do, phpMyAdmin is so much easier xD

Cause i can’t simply use

var mysql = require(‘mysql’);

var con = mysql.createConnection({
host: “localhost”,
user: " yourusername ",
password: " yourpassword "
});

con.connect(function(err) {
if (err) throw err;
console.log(“Connected!”);
});

Cause i don’t have login information ._.
Or do i?


#9

You should actually be able to connect with that process using a passwordless root account. If you look at the contents of .mysql/run-mysqld.sh in that project (or better, in a remix of it) and also read https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization.html#data-directory-initialization-procedure you can see how MySQL is being started in that project.

If you want something more user-friendly on the MySQL side of things, your best bet may be to host the database elsewhere; that’s not a configuration that we’re currently optimizing for and we don’t have any immediate plans to improve that workflow.

It’s possible that someone else has this running in Glitch or that someone might be able to offer some more specific instructions, but given that it’s outside of the Glitch’s current areas of focus it’s going to be naturally more technically complex than other options might be.


#10

Okay, thank you very much for your time and support. :smiley: Have a great day further.