{"id":21700513,"url":"https://github.com/tafara-n/alx-backend-storage","last_synced_at":"2026-02-28T14:31:13.566Z","repository":{"id":247710876,"uuid":"826637758","full_name":"Tafara-N/alx-backend-storage","owner":"Tafara-N","description":"Introduction to Backend Storage.","archived":false,"fork":false,"pushed_at":"2024-08-31T14:48:06.000Z","size":93556,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T03:51:14.491Z","etag":null,"topics":["mysql-advanced","no-sql","redis-basic"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tafara-N.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-10T05:07:12.000Z","updated_at":"2024-08-31T14:48:09.000Z","dependencies_parsed_at":"2024-08-18T10:43:42.474Z","dependency_job_id":"4a6f69f1-63d3-46a7-946a-9ccd2e5a63cc","html_url":"https://github.com/Tafara-N/alx-backend-storage","commit_stats":null,"previous_names":["tafara-n/alx-backend-storage"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tafara-N%2Falx-backend-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tafara-N%2Falx-backend-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tafara-N%2Falx-backend-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tafara-N%2Falx-backend-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tafara-N","download_url":"https://codeload.github.com/Tafara-N/alx-backend-storage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253828903,"owners_count":21970803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mysql-advanced","no-sql","redis-basic"],"created_at":"2024-11-25T20:14:31.771Z","updated_at":"2025-10-29T23:08:58.835Z","avatar_url":"https://github.com/Tafara-N.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction to Backend Storage: MySQL, MongoDB and Redis.\n\n## Table of Content\n- [Author](#author)\n- [Description](#description)\n___\n\n- [MySQL Advanced](0x00-MySQL_Advanced/README.md)\n- [NoSQL: MongoDB](0x01-NoSQL/README.md)\n- [NoSQL: Redis](0x02-redis_basic/README.md)\n___\n\n# Description\n\n1. # MySQL Advanced\n\n## Concepts\n\n*For this project, we expect you to look at this concept:*\n\n# MySQL\n\n- [Advanced SQL](https://intranet.alxswe.com/concepts/555)\n\n## Resources\n\n**Read or watch:**\n- [MySQL cheatsheet](https://devhints.io/mysql)\n- [MySQL Performance: How To Leverage MySQL Database Indexing](https://www.liquidweb.com/blog/mysql-optimization-how-to-leverage-mysql-database-indexing/)\n- [Stored Procedure](https://www.w3resource.com/mysql/mysql-procedure.php)\n- [Triggers](https://www.w3resource.com/mysql/mysql-triggers.php)\n- [Views](https://www.w3resource.com/mysql/mysql-views.php)\n- [Functions and Operators](https://dev.mysql.com/doc/refman/5.7/en/functions.html)\n- [Trigger Syntax and Examples](https://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html)\n- [CREATE TABLE Statement](https://dev.mysql.com/doc/refman/5.7/en/create-table.html)\n- [CREATE PROCEDURE and CREATE FUNCTION Statements](https://dev.mysql.com/doc/refman/5.7/en/create-procedure.html)\n- [CREATE INDEX Statement](https://dev.mysql.com/doc/refman/5.7/en/create-index.html)\n- [CREATE VIEW Statement](https://dev.mysql.com/doc/refman/5.7/en/create-view.html)\n\n# Learning Objectives\nAt the end of this project, you are expected to be able to [explain to anyone](https://fs.blog/feynman-learning-technique/), **without the help of Google:**\n\n## General\n- How to create tables with constraints\n- How to optimize queries by adding indexes\n- What is and how to implement stored procedures and functions in MySQL\n- What is and how to implement views in MySQL\n- What is and how to implement triggers in MySQL\n\n# Requirements\n\n##General\n- All your files will be executed on Ubuntu 18.04 LTS using `MySQL 5.7` (version `5.7.30`)\n- All your files should end with a new line\n- All your SQL queries should have a comment just before (i.e. syntax above)\n- All your files should start by a comment describing the task\n- All SQL keywords should be in uppercase (`SELECT`, `WHERE`…)\n- A `README.md` file, at the root of the folder of the project, is mandatory\n- The length of your files will be tested using `wc`\n\n# More Info\n\n**Comments for your SQL file:**\n\n```bash\n$ cat my_script.sql\n-- 3 first students in the Batch ID=3\n-- because Batch 3 is the best!\nSELECT id, name FROM students WHERE batch_id = 3 ORDER BY created_at DESC LIMIT 3;\n$\n```\n\n**Use “container-on-demand” to run MySQL**\n\n- Ask for container `Ubuntu 18.04 - Python 3.7`\n- Connect via SSH\n- Or via the WebTerminal\n- In the container, you should start MySQL before playing with it:\n\n```bash\n$ service mysql start\n * MySQL Community Server 5.7.30 is started\n$\n$ cat 0-list_databases.sql | mysql -uroot -p my_database\nEnter password:\nDatabase\ninformation_schema\nmysql\nperformance_schema\nsys\n$\n```\n\n**In the container, credentials are `root/root`**\n\n## How to import a SQL dump\n\n```bash\n$ echo \"CREATE DATABASE hbtn_0d_tvshows;\" | mysql -uroot -p\nEnter password:\n$ curl \"https://s3.amazonaws.com/intranet-projects-files/holbertonschool-higher-level_programming+/274/hbtn_0d_tvshows.sql\" -s | mysql -uroot -p hbtn_0d_tvshows\nEnter password:\n$ echo \"SELECT * FROM tv_genres\" | mysql -uroot -p hbtn_0d_tvshows\nEnter password:\nid  name\n1   Drama\n2   Mystery\n3   Adventure\n4   Fantasy\n5   Comedy\n6   Crime\n7   Suspense\n8   Thriller\n$\n```\n\n2. # NoSQL\n\n# Resources\n\n**Read or watch:**\n- [NoSQL Databases Explained](https://riak.com/resources/nosql-databases/)\n- [What is NoSQL ?](https://www.youtube.com/watch?v=qUV2j3XBRHc)\n- [MongoDB with Python Crash Course - Tutorial for Beginners](https://www.youtube.com/watch?v=E-1xI85Zog8)\n- [MongoDB Tutorial 2 : Insert, Update, Remove, Query](https://www.youtube.com/watch?v=CB9G5Dvv-EE)\n- [Aggregation](https://www.mongodb.com/docs/manual/aggregation/)\n- [Introduction to MongoDB and Python](https://realpython.com/introduction-to-mongodb-and-python/)\n- [mongo Shell Methods](https://www.mongodb.com/docs/manual/reference/method/)\n- [Mongosh](https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh)\n\n# Learning Objectives\nAt the end of this project, you are expected to be able to [explain to anyone](https://fs.blog/feynman-learning-technique/), **without the help of Google:**\n\n## General\n- What NoSQL means\n- What is difference between SQL and NoSQL\n- What is ACID\n- What is a document storage\n- What are NoSQL types\n- What are benefits of a NoSQL database\n- How to query information from a NoSQL database\n- How to insert/update/delete information from a NoSQL database\n- How to use MongoDB\n\n# Requirements\n\n## MongoDB Command File\n- All your files will be interpreted/compiled on Ubuntu 18.04 LTS using `MongoDB` (version `4.2`)\n- All your files should end with a new line\n- The first line of all your files should be a comment: `// my comment`\n- A `README.md` file, at the root of the folder of the project, is mandatory\n- The length of your files will be tested using `wc`\n\n## Python Scripts\n- All your files will be interpreted/compiled on Ubuntu 18.04 LTS using `python3` (version `3.7`) and `PyMongo` (version `3.10`)\n- All your files should end with a new line\n- The first line of all your files should be exactly `#!/usr/bin/env python3`\n- A `README.md` file, at the root of the folder of the project, is mandatory\n- Your code should use the `pycodestyle` style (version `2.5.*`)\n- The length of your files will be tested using `wc`\n- All your modules should have a documentation ( `python3 -c 'print(__import__(\"my_module\").__doc__)'` )\n- All your functions should have a documentation ( `python3 -c 'print(__import__(\"my_module\").my_function.__doc__)'`)\n- Your code should not be executed when imported (by using `if __name__ == \"__main__\" :`)\n\n# More Info\n\n## Install MongoDB 4.2 in Ubuntu 18.04\n\n- [Official installation guide](https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/)\n\n```bash\n$ wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add -\n$ echo \"deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2\nmultiverse\" \u003e /etc/apt/sources.list.d/mongodb-org-4.2.list\n$ sudo apt-get update\n$ sudo apt-get install -y mongodb-org\n...\n$ sudo service mongod status\nmongod start/running, process 3627\n$ mongo --version\nMongoDB shell version v4.2.8\ngit version: 43d25964249164d76d5e04dd6cf38f6111e21f5f\nOpenSSL version: OpenSSL 1.1.1 11 Sep 2018\nallocator: tcmalloc\nmodules: none\nbuild environment:\ndistmod: ubuntu1804\ndistarch: x86_64\ntarget_arch: x86_64\n$\n$ pip3 install pymongo\n$ python3\n\u003e\u003e\u003e import pymongo\n\u003e\u003e\u003e pymongo.__version__\n'3.10.1'\n```\n\nPotential issue if documents creation doesn’t work or this error: `Data directory /data/db not found., terminating` ([source](https://bryantson.medium.com/fixing-data-db-not-found-error-in-macos-x-when-starting-mongodb-d7b82abb2479) and [source](https://stackoverflow.com/questions/37702957/mongodb-data-db-not-found))\n\n```bash\n$ sudo mkdir -p /data/db\n```\n\nOr if `/etc/init.d/mongod` is missing, please find here an example of the file:\n\n```bash\n#!/bin/sh\n### BEGIN INIT INFO\n# Provides:          mongod\n# Required-Start:    $network $local_fs $remote_fs\n# Required-Stop:     $network $local_fs $remote_fs\n# Should-Start:      $named\n# Should-Stop:\n# Default-Start:     2 3 4 5\n# Default-Stop:      0 1 6\n# Short-Description: An object/document-oriented database\n# Description:       MongoDB is a high-performance, open source, schema-free\n#                    document-oriented data store that's easy to deploy, manage\n#                    and use. It's network accessible, written in C++ and offers\n#                    the following features:\n#\n#                       * Collection oriented storage - easy storage of object-\n#                         style data\n#                       * Full index support, including on inner objects\n#                       * Query profiling\n#                       * Replication and fail-over support\n#                       * Efficient storage of binary data including large\n#                         objects (e.g. videos)\n#                       * Automatic partitioning for cloud-level scalability\n#\n#                    High performance, scalability, and reasonable depth of\n#                    functionality are the goals for the project.\n### END INIT INFO\n\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\nDAEMON=/usr/bin/mongod\nDESC=database\n\nNAME=mongod\n# Defaults.  Can be overridden by the /etc/default/$NAME\n# Other configuration options are located in $CONF file. See here for more:\n# http://dochub.mongodb.org/core/configurationoptions\nCONF=/etc/mongod.conf\nPIDFILE=/var/run/$NAME.pid\nENABLE_MONGOD=yes\n\n# Include mongodb defaults if available.\n# All variables set before this point can be overridden by users, by\n# setting them directly in the defaults file. Use this to explicitly\n# override these values, at your own risk.\nif [ -f /etc/default/$NAME ] ; then\n        . /etc/default/$NAME\nfi\n\n# Handle NUMA access to CPUs (SERVER-3574)\n# This verifies the existence of numactl as well as testing that the command works\nNUMACTL_ARGS=\"--interleave=all\"\nif which numactl \u003e/dev/null 2\u003e/dev/null \u0026\u0026 numactl $NUMACTL_ARGS ls / \u003e/dev/null 2\u003e/dev/null\nthen\n    NUMACTL=\"`which numactl` -- $NUMACTL_ARGS\"\n    DAEMON_OPTS=${DAEMON_OPTS:-\"--config $CONF\"}\nelse\n    NUMACTL=\"\"\n    DAEMON_OPTS=\"-- \"${DAEMON_OPTS:-\"--config $CONF\"}\nfi\n\n\nif test ! -x $DAEMON; then\n    echo \"Could not find $DAEMON\"\n    exit 0\nfi\n\nif test \"x$ENABLE_MONGOD\" != \"xyes\"; then\n    exit 0\nfi\n\n. /lib/lsb/init-functions\n\nSTARTTIME=1\nDIETIME=10                  # Time to wait for the server to die, in seconds\n                            # If this value is set too low you might not\n                            # let some servers to die gracefully and\n                            # 'restart' will not work\n\nDAEMONUSER=${DAEMONUSER:-mongodb}\nDAEMONGROUP=${DAEMONGROUP:-mongodb}\n\nset -e\n\nrunning_pid() {\n# Check if a given process pid's cmdline matches a given name\n    pid=$1\n    name=$2\n    [ -z \"$pid\" ] \u0026\u0026 return 1\n    [ ! -d /proc/$pid ] \u0026\u0026  return 1\n    cmd=`cat /proc/$pid/cmdline | tr \"\\000\" \"\\n\"|head -n 1 |cut -d : -f 1`\n    # Is this the expected server\n    [ \"$cmd\" != \"$name\" ] \u0026\u0026  return 1\n    return 0\n}\n\nrunning() {\n# Check if the process is running looking at /proc\n# (works for all users)\n\n    # No pidfile, probably no daemon present\n    [ ! -f \"$PIDFILE\" ] \u0026\u0026 return 1\n    pid=`cat $PIDFILE`\n    running_pid $pid $DAEMON || return 1\n    return 0\n}\n\nstart_server() {\n            # Start the process using the wrapper\n            start-stop-daemon --background --start --quiet --pidfile $PIDFILE \\\n                        --make-pidfile --chuid $DAEMONUSER:$DAEMONGROUP \\\n                        --exec $NUMACTL $DAEMON $DAEMON_OPTS\n            errcode=$?\n        return $errcode\n}\n\nstop_server() {\n# Stop the process using the wrapper\n            start-stop-daemon --stop --quiet --pidfile $PIDFILE \\\n                        --retry 300 \\\n                        --user $DAEMONUSER \\\n                        --exec $DAEMON\n            errcode=$?\n        return $errcode\n}\n\nforce_stop() {\n# Force the process to die killing it manually\n        [ ! -e \"$PIDFILE\" ] \u0026\u0026 return\n        if running ; then\n                kill -15 $pid\n        # Is it really dead?\n                sleep \"$DIETIME\"s\n                if running ; then\n                        kill -9 $pid\n                        sleep \"$DIETIME\"s\n                        if running ; then\n                                echo \"Cannot kill $NAME (pid=$pid)!\"\n                                exit 1\n                        fi\n                fi\n        fi\n        rm -f $PIDFILE\n}\n\n\ncase \"$1\" in\n  start)\n        log_daemon_msg \"Starting $DESC\" \"$NAME\"\n        # Check if it's running first\n        if running ;  then\n            log_progress_msg \"apparently already running\"\n            log_end_msg 0\n            exit 0\n        fi\n        if start_server ; then\n            # NOTE: Some servers might die some time after they start,\n            # this code will detect this issue if STARTTIME is set\n            # to a reasonable value\n            [ -n \"$STARTTIME\" ] \u0026\u0026 sleep $STARTTIME # Wait some time\n            if  running ;  then\n                # It's ok, the server started and is running\n                log_end_msg 0\n            else\n                # It is not running after we did start\n                log_end_msg 1\n            fi\n        else\n            # Either we could not start it\n            log_end_msg 1\n        fi\n        ;;\n  stop)\n        log_daemon_msg \"Stopping $DESC\" \"$NAME\"\n        if running ; then\n            # Only stop the server if we see it running\n                        errcode=0\n            stop_server || errcode=$?\n            log_end_msg $errcode\n        else\n            # If it's not running don't do anything\n            log_progress_msg \"apparently not running\"\n            log_end_msg 0\n            exit 0\n        fi\n        ;;\n  force-stop)\n        # First try to stop gracefully the program\n        $0 stop\n        if running; then\n            # If it's still running try to kill it more forcefully\n            log_daemon_msg \"Stopping (force) $DESC\" \"$NAME\"\n                        errcode=0\n            force_stop || errcode=$?\n            log_end_msg $errcode\n        fi\n        ;;\n  restart|force-reload)\n        log_daemon_msg \"Restarting $DESC\" \"$NAME\"\n                errcode=0\n        stop_server || errcode=$?\n        # Wait some sensible amount, some server need this\n        [ -n \"$DIETIME\" ] \u0026\u0026 sleep $DIETIME\n        start_server || errcode=$?\n        [ -n \"$STARTTIME\" ] \u0026\u0026 sleep $STARTTIME\n        running || errcode=$?\n        log_end_msg $errcode\n        ;;\n  status)\n\n        log_daemon_msg \"Checking status of $DESC\" \"$NAME\"\n        if running ;  then\n            log_progress_msg \"running\"\n            log_end_msg 0\n        else\n            log_progress_msg \"apparently not running\"\n            log_end_msg 1\n            exit 1\n        fi\n        ;;\n  # MongoDB can't reload its configuration.\n  reload)\n        log_warning_msg \"Reloading $NAME daemon: not implemented, as the daemon\"\n        log_warning_msg \"cannot re-read the config file (use restart).\"\n        ;;\n\n  *)\n        N=/etc/init.d/$NAME\n        echo \"Usage: $N {start|stop|force-stop|restart|force-reload|status}\" \u003e\u00262\n        exit 1\n        ;;\nesac\n\nexit 0\n```\n\n## Use “container-on-demand” to run MongoDB\n\n- Ask for container `Ubuntu 18.04 - MongoDB`\n- Connect via SSH\n- Or via the WebTerminal\n- In the container, you should start MongoDB before playing with it:\n\n```bash\n$ service mongod start\n* Starting database mongod [ OK ]\n$\n$ cat 0-list_databases | mongo\nMongoDB shell version v4.2.8\nconnecting to: mongodb://127.0.0.1:27017/?compressors=disabled\u0026gssapiServiceName=mongodb\nImplicit session: session { \"id\" : UUID(\"70f14b38-6d0b-48e1-a9a4-0534bcf15301\") }\nMongoDB server version: 4.2.8\nadmin 0.000GB\nconfig 0.000GB\nlocal 0.000GB\nbye\n$\n```\n\n3. # Redis\n\n![Redis is a fancy Hash Table!!](redis_is_fancy_hash_table.png)\n\n# Resources\n\n**Read or watch:**\n- [Redis Crash Course Tutorial](https://www.youtube.com/watch?v=Hbt56gFj998)\n- [Redis commands](https://redis.io/docs/latest/commands/)\n- [Redis python client](https://redis-py.readthedocs.io/en/stable/)\n- [How to Use Redis With Python](https://realpython.com/python-redis/)\n\n## Learning Objectives\n- Learn how to use redis for basic operations\n- Learn how to use redis as a simple cache\n\n# Requirements\n\n- All of your files will be interpreted/compiled on Ubuntu 18.04 LTS using - `python3` (version `3.7`)\n- All of your files should end with a new line\n- A `README.md` file, at the root of the folder of the project, is mandatory\n- The first line of all your files should be exactly `#!/usr/bin/env python3`\n- Your code should use the `pycodestyle` style (version 2.5)\n- All your modules should have documentation (`python3 -c 'print(__import__(\"my_module\").__doc__)'`)\n- All your classes should have documentation (`python3 -c 'print(__import__(\"my_module\").MyClass.__doc__)'`)\n- All your functions and methods should have documentation (`python3 -c 'print(__import__(\"my_module\").my_function.__doc__)'` and `python3 -c 'print(__import__(\"my_module\").MyClass.my_function.__doc__)'`)\n- A documentation is not a simple word, it’s a real sentence explaining what’s the purpose of the module, class or method (the length of it will be verified)\n- All your functions and coroutines must be type-annotated.\n\n## Install Redis on Ubuntu 18.04\n\n```bash\n$ sudo apt-get -y install redis-server\n$ pip3 install redis\n$ sed -i \"s/bind .*/bind 127.0.0.1/g\" /etc/redis/redis.conf\n```\n\n## Use Redis in a container\n\nRedis server is stopped by default - when you are starting a container, you should start it with: `service redis-server start`\n\n## Author\n\n**Tafara Nyamhunga - [Github](https://github.com/tafara-n) / [Twitter](https://twitter.com/tafaranyamhunga)**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftafara-n%2Falx-backend-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftafara-n%2Falx-backend-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftafara-n%2Falx-backend-storage/lists"}