Giter Club home page Giter Club logo

databases's Introduction

If you are following the HackYourFuture curriculum we recommend you to start with module 1: HTML/CSS/GIT. To get a complete overview of the HackYourFuture curriculum first, click here.

Please help us improve and share your feedback! If you find better tutorials or links, please share them by opening a pull request.

Module #6 - Databases: Store and retrieve data with MySQL (Backend)

Databases

Have you ever thought about how your brain remembers things? It happens automatically for humans, but that's not the case for computers. Any time you go to a website and fill in some details in a form for example, that information needs to be saved somewhere. This "somewhere" is called a database.

In this module, you learn all about a fundamental part of any software application: how to (safely) store data, so that it can be used on-demand. You will learn how to structure and group data so that your apps know where to find and store the correct data.

Before you start

Before your first session, you need to install the necessary software: MySQL. This differs depending on your operating system.

During the installation of MySQL v8, in one of the last steps, you must configure the password encryption. Here is a screenshot of the step. You must select Legacy for all the given scripts to be able to connect.

Setup your first database

In this document, you find all the instructions on how to setup your first database. Most of the commands are done in the command line, so make sure you have yours open before you start.

Step 1: Logging in with the root user

To get started with your new MySQL client, we first have to login with the root user.

A root user, also known as a superuser is a special user account that has access to all commands and files of any particular software.

In Windows OS, if you click on the Start menu and type MySQL Command line Client, then the MySQL Command Line Client gives you a msql> prompt after typing in your root password. Note that this password is the one you used for the root user of the MySQL during the installation. Linux and MAC users can execute mysql -uroot -p and then type your root password.

Step 2: Creating a hyfuser account

After loggin in with the root user, it's time to create the account that you will use for this module. Execute the following commands, one after the other:

# Step 1: This command creates a user 'hyfuser' with password 'hyfpassword' for the database server at 'localhost'

mysql> create user 'hyfuser'@'localhost' identified with mysql_native_password by 'hyfpassword';

# If this does not work try the alternative command:

mysql> create user 'hyfuser'@'localhost' identified by 'hyfpassword';

# Step 2: This command gives all permissions to user 'hyfuser'. The (*.*) means every table of every database.

mysql> grant all privileges on *.* to 'hyfuser'@'localhost';

# Step 3: This command flushes all privileges so that mysql reloads the grant table and our changes are enabled

msyql> flush privileges;

# Step 4: This command creates a database named 'userdb'

mysql> create database userdb;

Step 3: Installing MySQL driver to use with Node.js

We want to use MySQL with JavaScript and to this end, we use the following package. You can create a project wherever you want and install it. To test that everything is working, you can use the connection-test.js file. If you run it it should output The solution is: 2.

Learning goals

In this module, you get familiar with the complexity of storing data. By the end of it, you have learned:

  • What is the meaning of a database entity;
  • How to work with Structured Query Language (SQL);
  • All about the relational model;
  • How to recognise the basic setup of a database;
  • Know about MySQL as an example of a relational database system;
  • Know NoSQL databases, with an emphasis on MongoDB.

How to use this repository

Repository content

This repository consists of 3 essential parts:

  1. README: this document contains all the required theory you need to understand while working on the weekly assignment. It contains not only the right resources to learn about the concepts, but also lectures done by HackYourFuture mentors. This is the first thing you should start with every week
  2. MAKEME: this document contains the instructions for each week's assignment. Start with the exercises rather quickly, so that you can ground the concepts you read about earlier.
  3. LESSONPLAN: this document is meant for mentors as a reference. However, as a trainee don't be shy to take a look at it as well!

How to study

Let's say you are just starting out with the Databases module. This is what you do:

  1. The week always starts on Wednesday. First thing you'll do is open the README.md for that week. For the first week of Databases, that would be Week1 Reading.
  2. You spend Wednesday and Thursday going over the resources and try to get a basic understanding of the concepts. In the meanwhile, you must implement any feedback you received on the preceeding assignments (from the Node.js module).
  3. On Friday you start with the weekly assignment, found in the MAKEME.md. For the first week of Databases, that would be Assignment W1.
  4. You spend Friday and Saturday playing around with the exercises and write down any questions you might have.
  5. DEADLINE 1: You submit any question you might have before Saturday 23.59, in the cohort channel.
  6. On Sunday you attend the Q&A session. There will be no new material, instead your questions will be be discussed and you can learn from others.
  7. You spend Monday and Tuesday finalizing your assignment.
  8. DEADLINE 2: You submit your assignment to the right channels (GitHub) before Tuesday 23.59. If you can't make it on time, please communicate it with your mentor and Joséphine.
  9. Start the new week by going back to point 1!

In summary:

Weekflow

To have a more detailed overview of the guidelines, please read this document or ask your mentor/cohort on Slack!

Planning

Week Topic Readings Assignment Lesson Plan
1. What's a database, Entities, Data structures, Structured Query Language (SQL) Readings W1 Assignment W1 Lesson Plan W1
2. Identifiers, Relationships, Domain Modeling, Advanced SQL commands Readings W2 Assignment W2 Lesson Plan W2
3. Normalization, Transactions, SQL Injection, NoSQL basics (with MongoDB) Readings W3 Assignment W3 Lesson Plan W3
4. NoSQL advanced commands, Pagination, SQL vs NoSQL Readings W4 Assignment W4

Finished?

Did you finish the module? You're almost at the top!

If you feel ready for the next challenge, click here to go to React!

Copyright

The HackYourFuture curriculum is subject to CC BY copyright. This means you can freely use our materials, but just make sure to give us credit for it :)

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

databases's People

Contributors

acadavid avatar alexandersaid avatar allhandsondeck avatar breus avatar cgduncan7 avatar chris-gunawardena avatar danlaudk avatar dependabot[bot] avatar fatmahameed avatar filievski avatar gajduk avatar gijscor avatar ginastavropoulou avatar hatemkhattab avatar jasongwartz avatar jidarwish avatar josephinehyf avatar laurensrietveld avatar mkruijt avatar noergitkat avatar old-profile avatar robvk avatar sergperep avatar shadoo77 avatar stasel avatar tjebbee avatar tkaria avatar tomasvanrijsse avatar unmeshvrije avatar wilgert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

databases's Issues

Week3 Exercise 3 improvements

By week 3 the students are used to work with the promisified execQuery.

The exercise could be upgraded so there are less questions about the weirdness / old school approach.

const execQuery = util.promisify(connection.query.bind(connection));

async function getPopulationFromCountry(name, code) {
  // assuming that connection to the database is established and stored as conn
  return execQuery(
    `SELECT Population FROM `country` WHERE Name = '${name}' and code = '${code}'`
  );
}

Wrong Syntax in Week1 Readme File

Some of the apostrophes have to be changed into single quotes to run the code properly. The parts that have to be corrected in "setting up code" must be as shown in bullets:

  • create user 'hyfuser'@'localhost' identified with mysql_native_password by 'hyfpassword';
mysql> create user ‘hyfuser’@‘localhost’ identified with mysql_native_password by ‘hyfpassword’;
# This command creates a user 'hyfuser' with password 'hyfpassword' for
# the database server at 'localhost'
  • grant all privileges on . to 'hyfuser'@'localhost';
mysql> grant all privileges on *.* to ‘hyfuser’@‘localhost’;
# This command gives all permissions to user 'hyfuser'.
(*.*) means every table of every database.

Remove Set autocommit

Students where asking about set autocommit = 0
In my opinion we shouldn't mention this syntax and only keep the subject concise by only talking about START TRANSACTION, COMMIT and ROLLBACK
These keywords do the same as set autocommit but are better words that are also found in ORM's and even in other DBs.

Spell issue

[6.] Select the top 3 countries by population that their names start with the later ‘P’

later => letter

Remove content concerning super keys and candidate keys

This subject is highly theoretical (and even feels unnatural to and to students) when designing a database.

IMHO without this topic they would be just a good in database designing as without it.
And i'd rather include some other topic like

  • how style your code around queries (models, migrations, seeds)
  • ORM

Full SQL Tutorial Video

I think the database module is complex as javascript modules. Students (we) are preparing their self to hardness and complexity of javascript but not to the database. I think they should be warned for the database module as they were warned for javascript. Because MySQL is one of the most important tools for us to keep it in our skills.

Briefly, there should be a useful full tutorial for SQL. Mostly preferred a video. I think a source as a video with examples in it is the most efficient way to learn. Therefore before the week1 of the database, this full tutorial of MySQL could be very useful:
https://www.youtube.com/watch?v=HXV3zeQKqGY

(And I have to say that I did not like the last part. It is better not to watch the last part which is the introduction to ERD. )

Elaborate on RDMBS vs NoSQL

it's not a 'versus' discussion, it's about what data to put in which db.
Most (big) projects these days use both types of DB's in a single project

MySQL is useful for most of the data in all applications. Every application needs to start relational for example with entities like users, companies, subscription etc. Since most of the data we deal with is relational by nature.

NoSQL is useful for:
○ data collection without the time to properly normalize it in advance (e.g. collect log data and user activity without knowing what to do with it)
○ search engines (e.g. ElasticSearch)
○ for caching (you can put all data in a single document, skipping joins and allowing duplicate data)

To bad MongoDB has been hyped and in use for general purposes.
This leads to skipping proper database design and will give trouble on schema changes

It's easy to simply store your JS objects as JSON in Mongo but thats just as easy in Postgress or MySQL.

Some comments from people wishing they never started using MongoDB:
https://www.reddit.com/r/node/comments/8r263o/why_should_i_use_mongodb_and_not_mysql_with_node/#thing_t1_e0pfb21

Missing an example for unique key

INSERT INTO database_reading_material (unique_key) VALUES ('An example of how to define a unique key when creating a table') 🙂

DB week2 Homework

Because of (uesr_id ) field in todo_items table don't accept a null value then We can add it directly in the query string or we can use it as a parameter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.