 #### What Will I Learn? - Download XAMPP for apache & MySQL server with PHPMyAdmin - installing MySQL package on nodejs - setup MySQL server on nodejs server #### Requirements - NodeJS [Download](https://nodejs.org/en/) - XAMPP [Download](https://www.apachefriends.org/download.html) #### Difficulty - Intermediate #### Tutorial Contents In this tutorial, you will learn how to install XAMPP, Install MySQL package and setup MySQL in NodeJS. #### Curriculum - [NodeJS Tutorials #1](https://utopian.io/utopian-io/@lonelywolf/nodejs-tutorials-1-creating-a-static-site-node-js) #### Setup MySQL ### Step 1 - Setup Your NodeJS server ``` var app = require('http').createServer(handler); var fs = require('fs'); app.listen(80); ``` `app` - creating the server. `fs` - import file system package `app.listen` - listening to the server. ``` function handler (req, res) { fs.readFile(__dirname + '/index.html', function (err, data) { if (err) { res.writeHead(500); return res.end('Error loading index.html'); } res.writeHead(200); res.end(data); }); } ``` this function will open the server and read the `index.html` file if you have one. if you want better explanation go to [here](https://utopian.io/utopian-io/@lonelywolf/nodejs-tutorials-1-creating-a-static-site-node-js) ### Step 2 - Install XAMPP we need XAMPP to use MySQL server and we need apache to run phpmyadmin for easy usage with MySQL. download the installer [here](https://www.apachefriends.org/download.html)     After all of these steps, press `Next` and start the installation process. when you have done you ready to run MySQL & Apache, we need apache to use phpmyadmin. Go to your xampp directory and open `apache_start` and `mysql_start`   if all done correctly go to `http://localhost/phpmyadmin`  ### Step 3 - Install MySQL package use the command ``` npm install mysql --save ``` this command installs the MySQL package to NodeJS so you can use it on your server and in your script.   import MySQL package to your server, ``` const mysql = require('mysql'); ``` ### Step 4 - Setup MySQL on NodeJS setup config json variable with `hostname`, `user`, `password`, `database` `hostname` - the hostname of the mysql server, for example, `127.0.0.1`. `user` - the username of the mysql server. `password` - the password of the mysql server. `database` - the database name. xampp defaults: `hostname: localhost`, `user: root`, `password: no password`. create a database with phpmyadmin, for example `mysql_example` ``` const config = { "host": "localhost", "user": "root", "password": "", "base": "mysql_example" }; ``` now we need to create the connection ``` var db = mysql.createConnection({ host: config.host, user: config.user, password: config.password, database: config.base }); ``` connection made with `hostname`, `user`, `password`, `database`. `mysql.createConnection` - this function creates the connection and put it to the `db` variable. now connect to the database ``` db.connect(function (error) { if (!!error) throw error; console.log('mysql connected to ' + config.host + ", user " + config.user + ", database " + config.base); }); ``` `db.connect` - connect to the database after you made the connection. if all done correctly you will see this reult  ##### part 2 - use MySQL to insert, import, update and delete data from the database Part 2 "What will I learn?" - Insert data into the database - Extract data from the database - Update data in the database - Delete data from the database <br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@lonelywolf/nodejs-tutorials-3-mysql-part-1">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>
author | lonelywolf | ||||||
---|---|---|---|---|---|---|---|
permlink | nodejs-tutorials-3-mysql-part-1 | ||||||
category | utopian-io | ||||||
json_metadata | "{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":27193779,"name":"node","full_name":"nodejs/node","html_url":"https://github.com/nodejs/node","fork":false,"owner":{"login":"nodejs"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","tutorial","mysql","nodejs","database"],"links":["https://nodejs.org/en/","https://www.apachefriends.org/download.html","https://utopian.io/utopian-io/@lonelywolf/nodejs-tutorials-1-creating-a-static-site-node-js","https://utopian.io/utopian-io/@lonelywolf/nodejs-tutorials-3-mysql-part-1"],"image":["https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Node.js_logo.svg/1200px-Node.js_logo.svg.png","https://cdn.utopian.io/posts/95ce86a1d879401e6829f091963fc210d3f2image.png","https://cdn.utopian.io/posts/0cd10b4e0960a26417261c734459534ad0a9image.png","https://cdn.utopian.io/posts/0d36cef666bd6375dac0845bf9f43f1b75c3image.png","https://cdn.utopian.io/posts/0ab1882916005889d39945a1b24b26abca3eimage.png","https://cdn.utopian.io/posts/04f72b3950ea71aae2706fc297f95fd4dbdcimage.png","https://cdn.utopian.io/posts/78d48264cbb246b5aa771f3fd7d2060fedbfimage.png","https://cdn.utopian.io/posts/fdbe8c725fc8dd480a3da765757e25dd11a1image.png","https://cdn.utopian.io/posts/add4c7f85cf9f74e2162c3cc27c05dabf969image.png","https://cdn.utopian.io/posts/a82cd9e56e7c38845aa7f27496b018e53b05image.png","https://cdn.utopian.io/posts/01a317e3fbc91272bf05c27a9c4f4985598cimage.png"],"moderator":{"account":"scipio","time":"2018-04-12T09:53:06.415Z","pending":false,"reviewed":false,"flagged":true},"questions":null,"score":null,"total_influence":null,"staff_pick":null,"config":{"questions":[{"question":"Does the tutorial address a minimum of 3 substantial concepts and no more than 5?","question_id":"tut-1","answers":[{"answer":"3-5 substantial concepts covered in the tutorial.","answer_id":1,"value":10},{"answer":"Less than 3 or more than 5 substantial concepts covered in the tutorial.","answer_id":2,"value":5},{"answer":"No substantial or recognisable concepts.","answer_id":3,"value":0}]},{"question":"Concepts covered in the tutorial are indicated in the post text with a short description of each concept and when appropriate, images?","question_id":"tut-2","answers":[{"answer":"Thorough text and images for concepts covered.","answer_id":1,"value":10},{"answer":"Minimal text and images.","answer_id":2,"value":5},{"answer":"No or very little text and images.","answer_id":3,"value":0}]},{"question":"Does the contributor provide supplementary resources, such as code and sample files in the contribution post or a GitHub repository?","question_id":"tut-3","answers":[{"answer":"Yes","answer_id":1,"value":10},{"answer":"No","answer_id":2,"value":0}]},{"question":"Is the tutorial part of a series?","question_id":"tut-4","answers":[{"answer":"Yes.","answer_id":1,"value":10},{"answer":"Yes, but first entry in the series.","answer_id":2,"value":5},{"answer":"No.","answer_id":3,"value":0}]},{"question":"Is there an outline for the tutorial content at the beginning of the post?","question_id":"tut-5","answers":[{"answer":"Yes.","answer_id":1,"value":10},{"answer":"Yes, but not detailed enough or does not cover all sections.","answer_id":2,"value":5},{"answer":"No.","answer_id":3,"value":0}]},{"question":"Does the writing style meet the Utopian standard considering formalness, informativeness and clarity of the content?","question_id":"c-1","answers":[{"answer":"It is formal, informative and well written with clear content.","answer_id":1,"value":10},{"answer":"It is informative with clear content but not formal enough.","answer_id":2,"value":5},{"answer":"The contribution could be more informative or contains unrelated information, formality and clarity of the content are good enough.","answer_id":3,"value":4},{"answer":"Not all sections were clear enough but overall holds value for the project.","answer_id":4,"value":2},{"answer":"Not at all.","answer_id":5,"value":0}]},{"question":"Was the provided category template for the editor followed?","question_id":"c-2","answers":[{"answer":"All points of the template were included with additional points as well.","answer_id":1,"value":5},{"answer":"The template was followed without additions.","answer_id":2,"value":4},{"answer":"The template was edited but the points were covered in different way.","answer_id":3,"value":3},{"answer":"Not all points of the template were covered in the contribution but the structure is clear enough.","answer_id":4,"value":3},{"answer":"The template was not followed but the structure is clear enough.","answer_id":5,"value":2},{"answer":"The contents are not clearly structured at all.","answer_id":6,"value":0}]},{"question":"Did the contributor tag other users?","question_id":"c-3","answers":[{"answer":"No other users were tagged by the contributor.","answer_id":1,"value":5},{"answer":"Used tags are reasonable and all tagged people are connected to the project and/or the contribution.","answer_id":2,"value":5},{"answer":"The contribution contains mentions of other users that are not directly related to the contribution but related in other ways.","answer_id":3,"value":2},{"answer":"The contributor misuses tagging of other users.","answer_id":4,"value":0}]},{"question":"Did the contributor ask for upvotes, resteems, follows or witness vote?","question_id":"c-4","answers":[{"answer":"No","answer_id":1,"value":5},{"answer":"Yes, but not in a way that disturbs readability. ","answer_id":2,"value":5},{"answer":"Yes.","answer_id":3,"value":0}]},{"question":"Was a graphical content like images, charts, videos or screenshots included?","question_id":"c-5","answers":[{"answer":"Yes, the graphical content is included and adds more value to the contribution.","answer_id":1,"value":5},{"answer":"No but the contribution works well without graphical content well.","answer_id":2,"value":4},{"answer":"Yes, but most of the graphical contentโs purpose is just for presentational matters.","answer_id":3,"value":3},{"answer":"No relevant or useful graphical content is included in the contribution.","answer_id":4,"value":0}]},{"question":"How would you rate the overall added value?","question_id":"c-6","answers":[{"answer":"Extraordinary value to both the project and the open source community overall.","answer_id":1,"value":20},{"answer":"Significant value to the project or open source community.","answer_id":2,"value":15},{"answer":"Some value to the project or open source community.","answer_id":3,"value":10},{"answer":"Little value to the project or open source community.","answer_id":4,"value":5},{"answer":"No obvious value to project or open source community.","answer_id":5,"value":0}]}]}}" | ||||||
created | 2018-04-12 02:15:45 | ||||||
last_update | 2018-04-12 09:53:15 | ||||||
depth | 0 | ||||||
children | 4 | ||||||
last_payout | 2018-04-19 02:15:45 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.604 HBD | ||||||
curator_payout_value | 0.129 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 4,734 | ||||||
author_reputation | 25,295,791,457,391 | ||||||
root_title | "NodeJS Tutorials #3 - MySQL Part 1" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 49,592,274 | ||||||
net_rshares | 184,928,641,990 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
cmp2020 | 0 | 15,795,324,930 | 24% | ||
remlaps1 | 0 | 19,866,492,395 | 24% | ||
cub1 | 0 | 51,942,207,766 | 24% | ||
remlaps2 | 0 | 4,151,760,795 | 100% | ||
lisa.palmer | 0 | 1,811,596,214 | 24% | ||
cub2 | 0 | 90,376,477 | 100% | ||
davidmendel | 0 | 21,958,019,462 | 100% | ||
arrap | 0 | 69,137,902 | 100% | ||
opaulo | 0 | 33,599,063,403 | 8% | ||
lonelywolf | 0 | 1,575,644,538 | 100% | ||
josephace135 | 0 | 11,966,662,964 | 100% | ||
maxpatternman | 0 | 9,750,446,967 | 100% | ||
properfraction | 0 | 575,166,076 | 100% | ||
layphyu | 0 | 596,219,548 | 100% | ||
nozokiumi | 0 | 450,166,978 | 100% | ||
glitterbot | 0 | 10,730,355,575 | 64.1% |
Read my profile if you want me to resteem your blog post to my 33,200+ followers. https://steemit.com/@a-0-0
author | a-0-0 |
---|---|
permlink | re-lonelywolf-nodejs-tutorials-3-mysql-part-1-20180412t021600306z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"links":["https://steemit.com/@a-0-0"],"app":"steemit/0.1"} |
created | 2018-04-12 02:16:03 |
last_update | 2018-04-12 02:16:03 |
depth | 1 |
children | 0 |
last_payout | 2018-04-19 02:16:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 108 |
author_reputation | -4,863,186,238,920 |
root_title | "NodeJS Tutorials #3 - MySQL Part 1" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 49,592,308 |
net_rshares | -4,495,170,782 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
mack-bot | 0 | -4,495,170,782 | -0.03% |
Hi, this contribution of yours **cannot be approved** because: - it only covers a fairly basic setting-things-up explanation (part 1, which you by itself explained fine); - yet when it seemed to get interesting (part 2) the tutorial ended; - to get a Utopian upvote, I want you to always do your utmost best, be as complete and in-depth as possible, and to produce really valuable tutorials. It's better to explain too much than too little; - please don't delete this either, but just continue with your remaining mySQL tutorials, and cover some more topics that are not too trivial in there. Good luck! @scipio ---------------------------------------------------------------------- Need help? Write a ticket on https://support.utopian.io. Chat with us on [Discord](https://discord.gg/uTyJkNm). **[[utopian-moderator]](https://utopian.io/moderators)**
author | scipio | ||||||
---|---|---|---|---|---|---|---|
permlink | re-lonelywolf-nodejs-tutorials-3-mysql-part-1-20180412t095637104z | ||||||
category | utopian-io | ||||||
json_metadata | {"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"} | ||||||
created | 2018-04-12 09:56:39 | ||||||
last_update | 2018-04-12 09:56:39 | ||||||
depth | 1 | ||||||
children | 2 | ||||||
last_payout | 2018-04-19 09:56:39 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.321 HBD | ||||||
curator_payout_value | 0.000 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 854 | ||||||
author_reputation | 34,229,826,851,736 | ||||||
root_title | "NodeJS Tutorials #3 - MySQL Part 1" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 49,646,991 | ||||||
net_rshares | 109,921,829,568 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
scipio | 0 | 109,129,870,950 | 100% | ||
lonelywolf | 0 | 791,958,618 | 100% |
`It's better to explain too much than too little`, maybe your'e true haha :) I didn't want to make this post too much detailed so I thought 2 parts will be better. thanks!
author | lonelywolf | ||||||
---|---|---|---|---|---|---|---|
permlink | re-scipio-re-lonelywolf-nodejs-tutorials-3-mysql-part-1-20180412t095915740z | ||||||
category | utopian-io | ||||||
json_metadata | {"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"} | ||||||
created | 2018-04-12 09:59:21 | ||||||
last_update | 2018-04-12 09:59:21 | ||||||
depth | 2 | ||||||
children | 0 | ||||||
last_payout | 2018-04-19 09:59:21 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.000 HBD | ||||||
curator_payout_value | 0.000 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 171 | ||||||
author_reputation | 25,295,791,457,391 | ||||||
root_title | "NodeJS Tutorials #3 - MySQL Part 1" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 49,647,323 | ||||||
net_rshares | 0 |
You can check my part 2 I think I did a great job there hh :)
author | lonelywolf |
---|---|
permlink | re-scipio-re-lonelywolf-nodejs-tutorials-3-mysql-part-1-20180413t051037222z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-04-13 05:10:42 |
last_update | 2018-04-13 05:10:42 |
depth | 2 |
children | 0 |
last_payout | 2018-04-20 05:10:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 61 |
author_reputation | 25,295,791,457,391 |
root_title | "NodeJS Tutorials #3 - MySQL Part 1" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 49,794,660 |
net_rshares | 0 |