1

First off, mysql is completely new to me, so please hold that in mind, when reading my question.

I have finished building a socket chat, that runs on a node server, and now I want to connect a database to it, so I can store users and their conversations. I have read various tutorials and guides, but all assume you know just a little bit.

In command prompt, inside my project's folder, I have installed mysql, which is now located in the node-modules folder. Afterwards, I have manually added it as a dependency in my JSON file.

I have then set up a connection in the server.js file:

var mysql = require('mysql');
var connection = mysql.createConnection({
	host: 'localhost',
	user: 'root',
	password: ''
});

connection.connect(function(err) {
	if (err) {
		console.error('error connecting: ' + err.stack);
    	return;
	} 

	console.log('connected as id ' + connection.threadId);
});

So where do I go from here? I thought I would be able to create a database using this command:mysql -u root -e 'CREATE DATABASE node' but that doesn't work.

1 Answer 1

3

first of all don't use mysql for chat . its not meant for chat db. because its not that fast. one thing you can do is use redis for chat db only. and for other relational stuff you can use mysql.

https://dzone.com/articles/using-redis-with-nodejs-and-socketio

Sign up to request clarification or add additional context in comments.

2 Comments

The thing is that, this chat is only a small part of a larger project, an app, that offers many other things than just a chat. And mysql is already used for other parts of the app.
Step 1 : make a table to store the data,Step:2 follow this documentation its totally self explanatory github.com/mysqljs/mysql

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.