Skip to content
← Back to Community
How do I install mySQL on my Project
Profile icon
OblivionTDW

https://repl.it/@OblivionTDW/Realm

I am having trouble with my project. I want to be able to store the users info that login to my website, but I can't do that because i don't know how to install mysql on my project. Does anyone know how to? I'm a little frustrated. XD

Voters
Profile icon
Aryan2902
Profile icon
VarunShanker
Profile icon
Manzar
Profile icon
kpostal10
Profile icon
OblivionTDW
Comments
hotnewtop
Profile icon
kpostal10

Relooking at the repl link provided if you are wanting to do login and have a website and stuff it might be better for you to look into node.js and use express. I dont think you could really do a login with a simple html thing uless you call an external server.
You can do login information however there will be no "main" server for it so logging in will do nothing for them.
(If you switch to node.js there are more powerful ways to render html pages with custom user information, React.js, pug (different format doestn use <> but still lets you do html), handlebars, or e.js)

You can use MySQL with just plain js. However the database itself would have to be hosted externally from repl.it (you can not install mysql on repl.it)
The following is how you would do it using express
https://dev.to/achowba/build-a-simple-app-using-node-js-and-mysql-19me
And for what I think you are wanting to do you would want the session store for MySQL
var MySQLStore = require('express-mysql-session')(session);
const mysql = require("mysql");
https://www.npmjs.com/package/express-mysql-session

Quick example of some code.

const sessionoptions = { //checkExpirationInterval: 1000 * 60 * 15,// 15 min // How frequently expired sessions will be cleared; milliseconds. expiration: 1000 * 60 * 60 * 24 * 7,// 1 week // The maximum age of a valid session; milliseconds. createDatabaseTable: true,// Whether or not to create the sessions database table, if one does not already exist. schema: { tableName: 'sessions', columnNames: { session_id: 'session_id', expires: 'expires', data: 'data' } } }; const dbConnectionInfosession = { multipleStatements: true, connectionLimit : 10, host: "localhost", user: "root", password: config.passwordDB, database: "session" } const poolsession = mysql.createPool(dbConnectionInfosession); const sessionStore = new MySQLStore(sessionoptions,poolsession);
app.use(session({ /*cookie: { secure: true, maxAge: 36000000 },*/ secret: secretRandom, saveUninitialized: false, resave: false, store: sessionStore, }));

Also side note from personal experince call the session store option first in your app chai. (app.use(sessionStore) -> app.use("someViewthing") -> app.get('/index'))
If you follow that

All code provided does work in a production enviorment.

Profile icon
staticvoidliam7
Profile icon
OblivionTDW

Thank you guys or gals for all of your help, I just have one question, you guys said that I can use node.JS for my project, In that case, Do I still use Node.js in my current project and will is work or do I have to try and transfer my files to a different node.js project?

Profile icon
kpostal10

@OblivionTDW node.js is seprated from the HTML / css / js repl. You would click new repl and select Nodejs (javascript) and that will be the repl you run.
You will have to transfer all the files over. The main website libary for js is called "express" https://www.npmjs.com/package/express

Profile icon
ArchieMaclean

I don't think you can use mySQL with just javascript. You will have to create a php file. There is a tutorial on php databases here: https://www.w3schools.com/php/php_mysql_intro.asp but I am not sure if this works on repl. Good luck!
Please upvote if this helps :)

Profile icon
kpostal10

@ArchieMaclean You can do mysql with javascript you dont need some type of external file thing. I have before and its really powerful when it comes to data storage for a javascript application.

Profile icon
ArchieMaclean

@kpostal10 ok, that's cool. I didn't know about that :)
Sorry for posting misinformation :)

Profile icon
kpostal10

@ArchieMaclean All good, all you did was Cunningham's law "the best way to get the right answer on the internet is not to ask a question; it's to post the wrong answer."

Profile icon
ArchieMaclean

@kpostal10 That's actually true

Profile icon
kpostal10

@ArchieMaclean Re looking at it he is using a html / css / js repl so what you put might be more valible, mine is a node.js implementation (I have since updated my main post above) where the "server" handles the login and displaying of webpages and allows the rendering of custom webpages where user information (varibles) can be passed through. However I dont think doing the type of repl he has currently can do a login system because of how it functions.

Profile icon
Kawli

,