PART 5 of 5  •  about 19 class hours

Modern MySQL, Admin & Projects

JSON and modern SQL, users, security and backups, MySQL inside Python, Node.js and PHP apps, capstone projects and your career.

17

JSON & Modern SQL Features

10 examples  •  4 h
18

Users, Security, Backup & Administration

10 examples  •  5 h
19

MySQL in Real Applications

10 examples  •  5 h
20

Capstone Projects & Career

10 examples  •  5 h
🚀
mysql>
SQL:2023  •  MySQL 9.7 LTS
BrainBit Infotech, Ranchi  |  Complete MySQL Course  |  Keys: ← → navigate   M menu   L SQL Lab   F fullscreen
M17

JSON & Modern SQL Features

Modern apps send and receive JSON. MySQL can store JSON, search inside it, index it, turn it into rows with JSON_TABLE and build JSON for APIs - all with standard SQL:2016/2023 features.

  • The JSON data type
  • JSON_OBJECT, JSON_ARRAY
  • -> and ->> paths
  • JSON_SET, JSON_REMOVE, JSON_CONTAINS
  • JSON_TABLE: JSON to rows
  • JSON_ARRAYAGG and JSON_OBJECTAGG
  • Generated columns and multi-valued indexes
  • JSON schema validation; VECTOR in MySQL 9
YOU WILL BUILD:
Flexible product specsOrder import from JSONAPI response built in SQL
🧩
about 4 hours
10 practice examples: 5 Easy • 3 Medium • 2 Hard
Complete MySQL Course  |  BrainBit Infotech, Ranchi
M17Where is this used in real work?

JSON is how apps talk

api.jharkhandbazaar.in/v1/products/5
{
  "id": 5,
  "name": "Bluetooth Speaker",
  "price": 1899.00,
  "specs": {"battery_hrs": 12, "colour": "black"},
  "tags": ["audio", "wireless", "bestseller"]
}
📱

Mobile apps and APIs

Android apps, React sites and payment gateways exchange JSON. MySQL can produce and read it directly.
🧩

Flexible attributes

A saree has fabric and length; a phone has RAM and battery. A JSON column stores different specs without 50 empty columns.
📊

Logs and settings

App settings, form answers, webhook payloads (UPI, courier) are stored as JSON and queried later.
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Concept

The JSON type and building JSON

  • A JSON column checks that the text is valid JSON - invalid JSON is rejected (ERROR 3140).
  • JSON_OBJECT('key', value, ...) and JSON_ARRAY(a, b, ...) build JSON safely (quotes and escaping are done for you).
  • MySQL stores JSON in a fast binary format and keeps keys sorted.
📜 SQL standard vs MySQL
SQL:2023 standardSQL:2016 added JSON functions; SQL:2023 added a JSON data type
MySQL 9.7JSON type since 5.7, JSON_TABLE since 8.0, plus MySQL-only helpers like ->>
json.sql
REAL RUN
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Animated explainer

JSON paths: finding a value inside a document

{
  "name": "Bluetooth Speaker",
  "specs": {
     "battery_hrs": 12,
     "colour": "black" },
  "tags": [ "audio", "wireless", "bestseller" ]
}
$.name
$.specs.battery_hrs
specs->>'$.battery_hrs'
$.tags[0]
$.tags[1] / $.tags[*]
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Concept

Reading and changing JSON

NeedFunction
read a valuedoc->>'$.city' or JSON_UNQUOTE(JSON_EXTRACT(doc,'$.city'))
change / add a keyJSON_SET(doc, '$.city', 'Ranchi')
remove a keyJSON_REMOVE(doc, '$.old')
array contains?JSON_CONTAINS(tags, '"audio"') or 'audio' MEMBER OF (tags)
length / keysJSON_LENGTH(doc), JSON_KEYS(doc)
json_rw.sql
REAL RUN
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Concept

Modern MySQL: what else is new in 8.0 - 9.7

FeatureSinceExample
JSON_TABLE (SQL standard)8.0JSON_TABLE(doc, '$[*]' COLUMNS (...))
Multi-valued index on JSON arrays8.0.17INDEX ((CAST(tags->'$' AS CHAR(20) ARRAY)))
VALUES ROW() table constructor8.0.19VALUES ROW(1,'a'), ROW(2,'b')
TABLE statement8.0.19TABLE students; = SELECT * FROM students
INTERSECT / EXCEPT8.0.31M9
VECTOR data type9.0embedding VECTOR(384) for AI similarity search
JSON duality views9.4tables shown as JSON documents (REST-style)
VECTOR (MySQL 9.x) - shown, not run in our labAI apps turn text into lists of numbers ("embeddings"). MySQL 9 can store them: CREATE TABLE docs (id INT, v VECTOR(3)); INSERT INTO docs VALUES (1, STRING_TO_VECTOR('[0.1, 0.8, 0.3]'));. Our lab server is 8.0.46, so this was not run. Distance search functions depend on your edition (HeatWave).
TipUse JSON for truly flexible data. If you search or join on a field every day, make it a normal column (or a generated column with an index).
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Practice 1 of 10  •  Easy

Example 1: Store app settings as JSON

● Easy💼 Real project: Mobile app user preferences
Each user's settings live in one JSON column. New settings can be added later without ALTER TABLE.
ex01.sql
REAL RUN
✍ Try it yourself Add user 3 with theme "dark", language "bn" and no notifications (empty array).
JSON_OBJECT('theme','dark','lang','bn','notify',JSON_ARRAY())
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Practice 2 of 10  •  Easy

Example 2: Read a value with ->>

● Easy💼 Real project: Show the user's language in the app header
->> extracts a value as plain text so you can filter and display it like a normal column.
ex02.sql
REAL RUN
✍ Try it yourself List users who have "whatsapp" in notify.
WHERE 'whatsapp' MEMBER OF (prefs->'$.notify')
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Practice 3 of 10  •  Easy

Example 3: Update one key with JSON_SET

● Easy💼 Real project: Changing one setting without touching others
JSON_SET changes or adds keys; JSON_REMOVE deletes them. Other keys stay as they were.
ex03.sql
REAL RUN
✍ Try it yourself Append "push" to a notify array with JSON_ARRAY_APPEND.
JSON_ARRAY_APPEND(prefs, '$.notify', 'push')
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Practice 4 of 10  •  Easy

Example 4: Build JSON for an API

● Easy💼 Real project: REST API returning products
Instead of building JSON in PHP or Node, MySQL can return ready JSON for each row - one less step in the app.
ex04.sqlbazaar_setup.sql
REAL RUN
✍ Try it yourself Add the category name to the JSON (join categories).
JOIN categories c USING (category_id) ... 'category', c.name
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Practice 5 of 10  •  Easy

Example 5: Array of tags and MEMBER OF

● Easy💼 Real project: Tag filter on a blog or shop
Tags are a JSON array. MEMBER OF checks if a value is in the array; JSON_CONTAINS does the same with JSON input.
ex05.sql
REAL RUN
✍ Try it yourself Count posts per tag. (Hint: JSON_TABLE in the next examples, or try it after M7 + JSON_TABLE.)
SELECT t.tag, COUNT(*) FROM posts, JSON_TABLE(tags,'$[*]' COLUMNS(tag VARCHAR(20) PATH '$')) t GROUP BY t.tag;
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Practice 6 of 10  •  Medium

Example 6: Products with flexible specs

● Medium💼 Real project: Marketplace with many product types
Each category has different attributes. One specs JSON column holds them; queries read whichever keys they need.
ex06.sql
REAL RUN
✍ Try it yourself Find mobiles with at least 6 GB RAM.
specs->>'$.ram_gb' + 0 >= 6 (the + 0 turns text into a number)
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Practice 7 of 10  •  Medium

Example 7: JSON_TABLE: import an order from JSON

● Medium💼 Real project: Saving an order sent by a mobile app
The app sends the whole cart as JSON. JSON_TABLE turns the array into rows and columns, so one INSERT ... SELECT saves every item. ->> works only on columns; for a variable use the SQL-standard JSON_VALUE().
ex07.sqlbazaar_setup.sql
REAL RUN
✍ Try it yourself Add a column line_no FOR ORDINALITY to JSON_TABLE. What does it give?
A counter 1, 2, 3 for each array element.
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Practice 8 of 10  •  Medium

Example 8: Generated column + index on JSON

● Medium💼 Real project: Fast search inside JSON data
Searching inside JSON on every row is slow. A generated column copies a JSON value into a normal column automatically, and an index on it makes the search fast (EXPLAIN shows ref).
ex08.sql
REAL RUN
✍ Try it yourself Try to UPDATE the brand column directly. What happens?
ERROR 3105 - generated columns cannot be set; change the JSON instead.
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Practice 9 of 10  •  Hard

Example 9: Validate JSON with a schema CHECK

● Hard💼 Real project: Accepting webhook data from a payment gateway
JSON_SCHEMA_VALID checks the shape of a document (required keys, types, ranges). Used in a CHECK constraint, it rejects bad payloads at the door.
⚠ The error in this example is on purpose.
ex09.sql
REAL RUN
✍ Try it yourself Add a required "upi_id" string to the schema and test a payload without it.
Add "upi_id" to "required" and to "properties".
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Practice 10 of 10  •  Hard

Example 10: API response: customer with nested orders

● Hard💼 Real project: Mobile app "My orders" screen
JSON_ARRAYAGG collects each customer's orders (and their items) into nested JSON. One query = the complete API response; the app just sends it.
ex10.sqlbazaar_setup.sql
REAL RUN
✍ Try it yourself Return the same JSON for all Ranchi customers (one row each).
WHERE c.city = 'Ranchi' instead of the customer_id filter.
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Check your understanding

Quick Quiz

Click an answer. Wrong answers shake; the right one turns green and explains why.

Q1. prefs->>'$.lang' returns...
✔ ->> = extract + unquote.
Q2. Turn a JSON array into rows with...
✔ JSON_TABLE is the SQL-standard way.
Q3. Fast search on a JSON value: create...
✔ Index the generated column (or use a multi-valued index for arrays).
🎯
Your score: 0 / 3 (first try counts)
Answer all questions. Discuss any wrong answer with your partner before moving on.
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M17Module summary

Recap: JSON & Modern SQL Features

What you learned in M17

  • ✔The JSON type stores validated JSON in a fast binary format.
  • ✔Build with JSON_OBJECT / JSON_ARRAY; read with -> and ->>.
  • ✔JSON_SET / JSON_REMOVE change parts; MEMBER OF / JSON_CONTAINS search arrays.
  • ✔JSON_TABLE turns JSON into rows; JSON_ARRAYAGG builds nested JSON.
  • ✔Generated columns + indexes make JSON searches fast.
  • ✔MySQL 9 adds VECTOR for AI search and JSON duality views.
🏆

Module 17 complete!

You practised 10 real examples on a real MySQL server.

👉 Coming next

M18 Users, Security, Backup & Administration: keep the database safe: users, roles, SQL injection, backups.
Complete MySQL Course  |  Part 5  |  JSON & Modern SQL Features
M18

Users, Security, Backup & Administration

A database full of student marks, salaries and payments must be protected. Learn to create users with only the rights they need, stop SQL injection, watch the server, and take backups you can actually restore.

  • Users and hosts
  • CREATE / ALTER / DROP USER
  • GRANT, REVOKE, SHOW GRANTS
  • Roles for teams
  • Least privilege
  • SQL injection and prepared statements
  • information_schema, performance_schema, sys
  • Backup and restore with mysqldump
YOU WILL BUILD:
Read-only report userRole for data-entry staffTested backup + restore
🛡️
about 5 hours
10 practice examples: 5 Easy • 3 Medium • 2 Hard
Complete MySQL Course  |  BrainBit Infotech, Ranchi
M18Where is this used in real work?

Security and backups are not optional

🕵️
Data leaks
Leaked mobile numbers and Aadhaar data lead to fraud calls. India's DPDP Act 2023 makes organisations responsible for protecting personal data.
💉
SQL injection
One of the most common web attacks. A login box that builds SQL from text can be tricked into showing every user.
🔥
Disk failure / ransomware
Without a tested backup, years of school or shop records can vanish in one night.
👤
Too much power
An app that logs in as root can drop every database if it is hacked. Give each app only what it needs.
🔍
Audits
Government and bank auditors ask: who can see salaries? When was the last backup restored?
✅
This module
Users, roles, prepared statements, monitoring queries and a full backup-restore drill.
🏫

School ERP

Teachers enter marks, the accountant sees fees, the principal sees reports - three roles, one database.
🏢

Company servers

Developers get read-only access to production; only the DBA can change structure.
💼

DBA career

User management and backups are the daily work of a Database Administrator.
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Concept

Users: name + host + password

  • A MySQL account is 'user'@'host'. 'report'@'localhost' can log in only from the server itself; 'report'@'%' from anywhere (riskier).
  • Passwords are stored as hashes. MySQL 8/9 uses caching_sha2_password. (The old mysql_native_password plugin was removed in MySQL 9.0.)
  • A new user can log in but can do nothing until you GRANT privileges.
Never use root in appsCreate one user per application with only the needed rights. Keep root for the DBA.
users.sql
REAL RUN
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Animated explainer

Least privilege: give only what is needed

📊
report
SELECTINSERTDROP
✍️
clerk
SELECTINSERTUPDATEDELETE
🛒
shop_app
SELECTINSERTUPDATEDELETEDROP
🧑‍💻
DBA (root)
ALLGRANT
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Animated explainer

SQL injection: how the attack works and how ? stops it

SQL injection
StepSQL that runs
user types' OR '1'='1
app glues text... WHERE name = '' OR '1'='1'
MySQL readsname = '' OR '1'='1' → always TRUE
resultevery row leaked
prepared statementWHERE name = ? + value sent separately
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Practice 1 of 10  •  Easy

Example 1: Create a read-only report user

● Easy💼 Real project: Power BI / Excel dashboard connection
The dashboard only reads. GRANT SELECT ON school.* = read every table of the school database, nothing else.
ex01.sqlschool_setup.sql
REAL RUN
✍ Try it yourself Create report2 who can read only the students table.
GRANT SELECT ON school.students TO 'report2'@'localhost';
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Practice 2 of 10  •  Easy

Example 2: Grant on one database and test it

● Easy💼 Real project: Shop application account
Session A is the DBA (root). Session B is a real login as shop_app. Its rights work for SELECT and UPDATE, but DELETE, DROP and other databases are refused (ERROR 1142 / 1044).
⚠ The error in this example is on purpose.
grant_test.sqlsetup.sql
REAL RUN
✍ Try it yourself Grant DELETE only on the order_items table and test again.
GRANT DELETE ON bazaar.order_items TO 'shop_app'@'localhost';
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Practice 3 of 10  •  Easy

Example 3: Show grants of every app user

● Easy💼 Real project: Monthly access review
An auditor asks "who can do what?". SHOW GRANTS answers per user; mysql.user lists all accounts.
ex03.sqlschool_setup.sql
REAL RUN
✍ Try it yourself Which privilege does the teacher NOT have on enrollments?
DELETE (and everything on other tables).
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Practice 4 of 10  •  Easy

Example 4: Revoke a privilege

● Easy💼 Real project: Removing access when a role changes
A temporary clerk no longer needs to change data. REVOKE removes UPDATE but keeps SELECT. Then the account is locked.
ex04.sqlschool_setup.sql
REAL RUN
✍ Try it yourself Remove the user completely.
DROP USER 'temp_clerk'@'localhost';
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Practice 5 of 10  •  Easy

Example 5: Role for data-entry staff

● Easy💼 Real project: Many clerks, one set of rights
A role is a named bundle of privileges. Grant the role to each clerk; change the role once and every clerk gets the change. (Roles: MySQL 8.0+.)
ex05.sqlschool_setup.sql
REAL RUN
✍ Try it yourself Create a role accountant with SELECT on fees only and give it to a new user.
CREATE ROLE 'accountant'; GRANT SELECT ON school.fees TO 'accountant'; ...
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Practice 6 of 10  •  Medium

Example 6: Prepared statements in SQL

● Medium💼 Real project: Safe search and repeated queries
PREPARE compiles a statement with ? placeholders once; EXECUTE ... USING runs it with different values. Apps (PHP PDO, Python, Node) use exactly this protocol.
ex06.sqlschool_setup.sql
REAL RUN
✍ Try it yourself Prepare an INSERT for fees with 5 placeholders and execute it once.
PREPARE ins FROM 'INSERT INTO fees VALUES (?,?,?,?,?)'; EXECUTE ins USING @a,@b,@c,@d,@e;
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Practice 7 of 10  •  Medium

Example 7: Database size report (information_schema)

● Medium💼 Real project: Server capacity planning
information_schema.tables knows the size of every table. DBAs run this to plan disk space and find big tables.
ex07.sqlschool_setup.sqlbazaar_setup.sqlcompany_setup.sql
REAL RUN
✍ Try it yourself Find the biggest table on the whole server.
ORDER BY data_length + index_length DESC LIMIT 1 without the WHERE.
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Practice 8 of 10  •  Medium

Example 8: Backup and restore with mysqldump

● Medium💼 Real project: Nightly backup of a school server
mysqldump writes the whole database as SQL statements (CREATE + INSERT) into a file. --single-transaction takes a consistent copy without stopping the school. A backup is only real when you have tested the restore - so we restore into a new database and count rows.
backup.batschool_setup.sql
REAL RUN
✍ Try it yourself Schedule it every night with Windows Task Scheduler (a .bat file) and keep the last 7 files.
Put the mysqldump line in backup.bat with the date in the file name; delete files older than 7 days.
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Practice 9 of 10  •  Hard

Example 9: SQL injection on purpose, and the fix

● Hard💼 Real project: Login and search pages
Part 1 builds SQL by joining text (the unsafe way, like bad PHP code) - the attack string returns every student's mobile. Part 2 uses a prepared statement - the same input returns nothing.
ex09.sqlschool_setup.sql
REAL RUN
✍ Try it yourself Try the input Priya Kumari with the safe query. Does a normal search still work?
Yes - it returns Priya's row. Placeholders block only the attack, not real searches.
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Practice 10 of 10  •  Hard

Example 10: Security audit queries for a school server

● Hard💼 Real project: Quarterly security checklist
A real checklist as SQL: accounts that can log in from anywhere (%), accounts with global privileges, locked accounts and password ages. Run it every quarter and fix what it finds.
ex10.sqlschool_setup.sql
REAL RUN
✍ Try it yourself Fix the audit finding: lock old_dev and then drop it.
ALTER USER 'old_dev'@'%' ACCOUNT LOCK; DROP USER 'old_dev'@'%';
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Check your understanding

Quick Quiz

Click an answer. Wrong answers shake; the right one turns green and explains why.

Q1. 'report'@'localhost' can log in from...
✔ '%' would mean any host.
Q2. Best protection against SQL injection?
✔ Values are sent separately and never run as SQL.
Q3. A backup is trustworthy when...
✔ Always practise the restore.
🎯
Your score: 0 / 3 (first try counts)
Answer all questions. Discuss any wrong answer with your partner before moving on.
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M18Module summary

Recap: Users, Security, Backup & Administration

What you learned in M18

  • ✔Accounts are 'user'@'host'; MySQL 9 uses caching_sha2_password.
  • ✔GRANT the least privileges needed; REVOKE and LOCK when roles change.
  • ✔Roles bundle privileges for groups of staff.
  • ✔Prepared statements (?) stop SQL injection.
  • ✔information_schema / performance_schema / sys tell you about the server.
  • ✔mysqldump --single-transaction for backups - and test the restore.
🏆

Module 18 complete!

You practised 10 real examples on a real MySQL server.

👉 Coming next

M19 MySQL in Real Applications: connect MySQL to Python, Node.js and PHP programs.
Complete MySQL Course  |  Part 5  |  Users, Security, Backup & Administration
M19

MySQL in Real Applications

Real users never type SQL - apps do it for them. See how Python, Node.js and PHP programs connect to MySQL, run safe parameterised queries, use transactions and pools, and turn data into reports and APIs.

  • How apps talk to MySQL (drivers)
  • Connection settings and app users
  • Python: mysql-connector
  • Node.js: mysql2 (promises)
  • PHP: PDO
  • Placeholders in code (no SQL injection)
  • Transactions and connection pools
  • Reports, CSV and REST APIs
YOU WILL BUILD:
CSV fee report (Python)Products REST API (Node.js)Result portal back-end (PHP)
💻
about 5 hours
10 practice examples: 5 Easy • 3 Medium • 2 Hard
Complete MySQL Course  |  BrainBit Infotech, Ranchi
M19Where is this used in real work?

Every app has a database driver inside

🐍
Python
Data analysis, automation, Django sites, AI apps
pip install mysql-connector-python
🟩
Node.js
React/Next.js back-ends, APIs, real-time apps
npm install mysql2
🐘
PHP
WordPress, Laravel, most Indian business websites
PDO (built into PHP)
☕
Java
Banks, Android back-ends (JDBC)
mysql-connector-j
📊
Excel / Power BI
Reports and dashboards (ODBC connector)
MySQL ODBC 9.x
📱
Mobile apps
Flutter / Android apps call an API, and the API talks to MySQL
never connect a phone app directly!
🔗

Same SQL everywhere

The SQL you learned works unchanged inside every language. Only the connect / execute / fetch code differs.
🔐

Security rules

App user with least privilege (M18), placeholders for every value, passwords in config files, not in code shared on GitHub.
💼

Full-stack skill

A backend developer job = SQL + one language + an API. You now have the SQL part.
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Animated explainer

What happens inside an app when it uses MySQL

🔌
connect
connect(...)
➤
📝
prepare
WHERE city = %s
➤
▶️
execute
execute(sql, ('Ranchi',))
➤
📥
fetch
fetchall()
➤
🔓
commit / close
conn.close()
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Concept

Connection settings and where to keep them

SettingExampleNotes
hostlocalhost / 127.0.0.1cloud: the server address
port3306MySQL default
usershop_appan app user, never root
passwordShop#App2026keep in a .env / config file
databasebazaardefault schema
charsetutf8mb4for Hindi and emoji
Our labEvery program in this module really ran against MySQL with the app users shown in each setup.sql. Output was recorded from Python 3, Node.js 22 and PHP 8.3.
.env
# .env  (do NOT upload this file to GitHub)
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=shop_app
DB_PASS=Shop#App2026
DB_NAME=bazaar
Placeholders differ by languagePython mysql-connector: %s   Node mysql2: ?   PHP PDO: ? or :name. They all do the same job: value sent separately.
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Practice 1 of 10  •  Easy

Example 1: Python: connect and print the server version

● Easy💼 Real project: First step of any Python + MySQL project
mysql.connector.connect() opens the connection; a cursor runs SQL and fetches results. Install once with pip install mysql-connector-python.
connect.pybazaar_setup.sqlsetup.sql
REAL RUN
✍ Try it yourself Print also the number of products with SELECT COUNT(*) FROM products.
cur.execute(...); print(cur.fetchone()[0])
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Practice 2 of 10  •  Easy

Example 2: Python: read students with a placeholder

● Easy💼 Real project: Teacher's lookup tool
The city comes from the user, so it goes in as a parameter (%s), never glued into the SQL text. dictionary=True gives rows as dictionaries.
students.pyschool_setup.sqlsetup.sql
REAL RUN
In the run, "Ranchi" was typed at the City: prompt.
✍ Try it yourself Run it again and type Ranchi' OR '1'='1. What happens?
No rows - the whole text is treated as a city name (no SQL injection).
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Practice 3 of 10  •  Easy

Example 3: Node.js: list products with mysql2

● Easy💼 Real project: Back-end of a React shopping site
mysql2/promise works with async/await. execute() uses a real prepared statement with ?. Install: npm install mysql2.
products.jsbazaar_setup.sqlsetup.sql
REAL RUN
✍ Try it yourself Change the query to show only Grocery products (category_id 1).
WHERE category_id = ? with [1]
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Practice 4 of 10  •  Easy

Example 4: PHP PDO: insert safely

● Easy💼 Real project: Admission form of a PHP website
PDO with named placeholders (:name). The apostrophe in O'Brien is no problem - values are never pasted into the SQL. ERRMODE_EXCEPTION turns SQL errors into PHP exceptions.
admit.phpschool_setup.sqlsetup.sql
REAL RUN
✍ Try it yourself Insert a student with marks 150. What happens with the CHECK-free school table? (Then add a CHECK as in M5.)
It is accepted - the school table has no CHECK. Add CHECK (marks BETWEEN 0 AND 100).
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Practice 5 of 10  •  Easy

Example 5: Python: export a report to CSV

● Easy💼 Real project: Fee report for the accountant (opens in Excel)
The query result is written to a CSV file that opens directly in Excel. cur.description gives the column names for the header row. See the Files tab.
fee_report.pyschool_setup.sqlsetup.sql
REAL RUN
✍ Try it yourself Add a column "due" = 6000 - paid.
Add 6000 - IFNULL(SUM(f.amount),0) AS due to the SELECT.
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Practice 6 of 10  •  Medium

Example 6: Node.js: a small REST API on MySQL

● Medium💼 Real project: Mobile app back-end
Express + a mysql2 pool. Each URL runs one parameterised query and returns JSON. A Flutter or React app calls these URLs - it never talks to MySQL directly.
api.jsbazaar_setup.sqlsetup.sql
REAL RUN
✍ Try it yourself Add GET /api/categories that returns all categories.
app.get("/api/categories", async (req,res)=>{ const [r]=await pool.query("SELECT * FROM categories"); res.json(r); });
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Practice 7 of 10  •  Medium

Example 7: Python: a transaction for a fee payment

● Medium💼 Real project: Fee counter software
start_transaction / commit / rollback from Python. Any error - unknown student, or a value too long for the column - rolls everything back and the user sees a clear message.
pay_fee.pyschool_setup.sqlsetup.sql
REAL RUN
✍ Try it yourself Add a check that the amount is positive before inserting.
if amount <= 0: raise ValueError("Amount must be positive")
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Practice 8 of 10  •  Medium

Example 8: Connection pool in Node.js

● Medium💼 Real project: High-traffic website
Opening a connection is slow. A pool keeps a few connections open and lends them out. Here 6 requests share only 3 MySQL connections - look at the repeated connection ids.
pool.jsbazaar_setup.sqlsetup.sql
REAL RUN
✍ Try it yourself Change connectionLimit to 1. What do you notice about the connection ids?
All 6 requests use the same single connection, one after another.
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Practice 9 of 10  •  Hard

Example 9: Python: daily sales summary message

● Hard💼 Real project: Owner's WhatsApp / email summary
Three queries feed one text message for the shop owner. A scheduler (Windows Task Scheduler or cron) could run it every night and send it by email or WhatsApp API.
daily_summary.pybazaar_setup.sqlsetup.sql
REAL RUN
✍ Try it yourself Add yesterday's sales and the % change.
Run the first query again with day - timedelta(days=1).
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Practice 10 of 10  •  Hard

Example 10: Result portal back-end (PHP + MySQL)

● Hard💼 Real project: School / board result website
Two prepared queries build the JSON a result page needs: student details plus course scores, with a 404 answer for an unknown roll number. In the real site the roll comes from the URL.
result_api.phpschool_setup.sqlsetup.sql
REAL RUN
✍ Try it yourself Add the class rank of the student (hint: a window function from M11 in a third query).
SELECT r FROM (SELECT student_id, RANK() OVER (ORDER BY marks DESC) r FROM students) t WHERE student_id = ?
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Check your understanding

Quick Quiz

Click an answer. Wrong answers shake; the right one turns green and explains why.

Q1. In Python mysql-connector, the placeholder is...
✔ Values are passed as a tuple: execute(sql, (city,)).
Q2. Why use a connection pool?
✔ Opening a new connection for each request is slow.
Q3. After INSERT/UPDATE in code you must...
✔ Python mysql-connector does not autocommit by default.
🎯
Your score: 0 / 3 (first try counts)
Answer all questions. Discuss any wrong answer with your partner before moving on.
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M19Module summary

Recap: MySQL in Real Applications

What you learned in M19

  • ✔Apps use a driver: connect → prepare → execute → fetch → close.
  • ✔Connect as an app user with least privilege; keep passwords in config files.
  • ✔Python %s, Node ? and PHP ?/:name placeholders stop SQL injection.
  • ✔Commit or roll back transactions from code.
  • ✔Pools reuse connections for busy websites.
  • ✔SQL results become CSV reports, messages and JSON APIs.
🏆

Module 19 complete!

You practised 10 real examples on a real MySQL server.

👉 Coming next

M20 Capstone Projects & Career: build a complete project, publish it, and plan your SQL career.
Complete MySQL Course  |  Part 5  |  MySQL in Real Applications
M20

Capstone Projects & Career

Time to build something real. Pick a project, design it, fill it with data, write the reports, publish it on GitHub and talk about it confidently in interviews. Then plan your next steps as a SQL professional.

  • Choosing a capstone project
  • Planning: requirements to queries
  • Project folder, Git and README
  • Deploying a MySQL database
  • 10 complete mini projects
  • Career paths with SQL
  • Interview questions
  • Your certificate
YOU WILL BUILD:
Your own capstone projectA GitHub portfolio repoYour course certificate
🏆
about 5 hours
10 practice examples: 5 Easy • 3 Medium • 2 Hard
Complete MySQL Course  |  BrainBit Infotech, Ranchi
M20Where is this used in real work?

From learner to professional

📝
Plan
requirements, ER diagram
➤
🏗️
Build
tables, data, queries
➤
🚀
Publish
GitHub, README, demo
➤
💼
Apply
resume, interview, job
What recruiters look forOne complete project you can explain end-to-end beats ten half-finished ones. Show the ER diagram, 10 good queries, one view, one procedure and a backup script.
🏫

Local demand

Schools, hospitals, shops, CA firms and startups in Ranchi, Jamshedpur, Dhanbad and Patna need people who can build and report from databases.
🌐

Remote work

SQL skills are used in companies everywhere; remote and freelance data projects are common for people with a good portfolio.
📈

Growth path

SQL is the base for data analysis, backend development, data engineering and database administration.
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Concept

Plan your capstone in 8 steps

  1. 1
    Requirement: talk to a real user (a shop owner, your school office). Write 5-10 things the system must do.
  2. 2
    Entities: underline the nouns; draw the ER diagram (M12). Mark 1:N and M:N.
  3. 3
    Tables: write schema.sql with types, keys and constraints (M2, M5).
  4. 4
    Sample data: seed.sql with 20-50 realistic local rows per table (M3).
  5. 5
    Questions: write 10-15 report queries in queries.sql (M4-M11) with comments.
  6. 6
    Power features: one view, one procedure or trigger, indexes for the main searches (M13-M15).
  7. 7
    Safety: an app user, a backup script, a restore test (M18).
  8. 8
    Present: README with ER diagram image, how to run, screenshots of results.
project folder
my-library-db/
  README.md          <- what, why, ER diagram, how to run
  schema.sql         <- CREATE TABLE statements
  seed.sql           <- sample data
  queries.sql        <- 10-15 report queries
  programs.sql       <- views, procedures, triggers
  backup.bat         <- mysqldump script
  er-diagram.png     <- from MySQL Workbench
Time planAbout 10-12 class hours: 2 h design, 3 h tables + data, 4 h queries and programs, 2 h README and presentation.
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Concept

Git, GitHub and a README that gets you noticed

terminal
git init
git add schema.sql seed.sql queries.sql README.md
git commit -m "Library DB: schema, seed data and 12 reports"
git branch -M main
git remote add origin https://github.com/your-name/my-library-db.git
git push -u origin main
Never commit passwordsKeep .env and real customer data out of Git. Use made-up sample data.
README.md
# District Library Management (MySQL 9.7)
A database for a Ranchi district library: members, books,
issues, returns and fines.

## Tables
members, books, authors, book_authors, issues  (ER diagram below)

## How to run
mysql -u root -p < schema.sql
mysql -u root -p library < seed.sql

## Sample reports (queries.sql)
1. Overdue books with fine     2. Most issued books (window rank)
3. Members inactive for 90 days 4. Monthly issue trend

## Skills used
JOINs, GROUP BY, CTEs, window functions, triggers, indexes
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Concept

Putting a database online

☁️

Managed cloud MySQL

Oracle MySQL HeatWave, AWS RDS, Azure, Google Cloud SQL: backups, updates and monitoring are handled for you. Free tiers exist for learning.
🌐

Shared hosting (cPanel)

Most Indian hosting plans include MySQL + phpMyAdmin. Create the database in cPanel, then Import your .sql file.
🖥️

Your own VPS

Install MySQL on Ubuntu; set a strong root password, bind to localhost or a firewall, create app users, schedule backups.
✅

Go-live checklist

App user (not root), strong passwords, utf8mb4, indexes on search columns, daily backup + tested restore, slow query log on.
📊

Connect tools

Power BI / Excel via the MySQL ODBC connector for dashboards; Metabase or Grafana for live charts.
🔄

Upgrades

Stay on an LTS line (8.4 or 9.7). Test upgrades on a copy first with MySQL Shell's upgrade checker.
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Practice 1 of 10  •  Easy

Example 1: School result system

● Easy💼 Real project: School / coaching result module
Subjects as rows, then a report with total, percentage, division and rank in one query. A view makes it reusable for the website.
ex01.sql
REAL RUN
✍ Try it yourself Add a subject-wise topper report.
Rank inside PARTITION BY subject and keep rank 1.
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Practice 2 of 10  •  Easy

Example 2: Library management

● Easy💼 Real project: District / college library
Books, members and issues; the key daily report is the overdue list with the fine on a given date.
ex02.sql
REAL RUN
✍ Try it yourself Add a "most issued books" report.
GROUP BY book_id ORDER BY COUNT(*) DESC.
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Practice 3 of 10  •  Easy

Example 3: Shop billing

● Easy💼 Real project: Kirana / medical shop billing counter
Bills and bill items; the bill print shows each line with GST, and the day-end report totals cash vs UPI.
ex03.sql
REAL RUN
✍ Try it yourself Add a GST summary by rate (5%, 12%, 18%) for the GST return.
GROUP BY gst_pct with SUM of the GST part only.
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Practice 4 of 10  •  Easy

Example 4: Hostel / PG booking

● Easy💼 Real project: PG owner's room management
Rooms have beds; bookings link a tenant to a bed for a period. The vacancy report shows free beds per room today.
ex04.sql
REAL RUN
✍ Try it yourself List tenants whose booking ends in the next 30 days.
WHERE to_date BETWEEN '2026-11-25' AND '2026-12-25'
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Practice 5 of 10  •  Easy

Example 5: Blood bank donor directory

● Easy💼 Real project: NGO / hospital blood donor finder
Find eligible donors fast: right blood group, same city, and last donation at least 90 days ago (or never).
ex05.sql
REAL RUN
✍ Try it yourself Count donors per blood group and city (a pivot from M7).
GROUP BY blood_group, city
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Practice 6 of 10  •  Medium

Example 6: Hospital OPD and pharmacy

● Medium💼 Real project: Small hospital software
Visits, prescriptions and medicine stock. Reports: today's load per doctor and medicines that will run out after today's prescriptions.
ex06.sql
REAL RUN
✍ Try it yourself Add a trigger that reduces stock when a prescription is inserted (M15).
AFTER INSERT ON prescriptions: UPDATE medicines SET stock = stock - NEW.qty WHERE id = NEW.medicine_id;
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Practice 7 of 10  •  Medium

Example 7: E-commerce analytics (Jharkhand Bazaar)

● Medium💼 Real project: Online shop management dashboard
Using the bazaar database: best customers with their share of sales, and the repeat-customer rate - two numbers every e-commerce owner tracks.
ex07.sqlbazaar_setup.sql
REAL RUN
✍ Try it yourself Add the average days between orders for repeat customers (LAG from M11).
LAG(order_date) OVER (PARTITION BY customer_id ORDER BY order_date)
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Practice 8 of 10  •  Medium

Example 8: Bus ticket booking

● Medium💼 Real project: Ranchi - Patna bus booking
A UNIQUE key on (trip, seat) makes double booking impossible even if two people click at once. The seat map shows which seats are free.
⚠ The error in this example is on purpose.
ex08.sql
REAL RUN
✍ Try it yourself Show total revenue and occupancy % of trip 1.
SUM(fare), COUNT(*) * 100 / 8
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Practice 9 of 10  •  Hard

Example 9: Coaching institute ERP

● Hard💼 Real project: Coaching centre management (students, fees, attendance)
Two management reports from one design: fee defaulters (fee due minus paid) and attendance % with a warning below 75% - using a CTE and window-free aggregation.
ex09.sql
REAL RUN
✍ Try it yourself Turn this into a view v_student_status and a procedure that lists only defaulters of one batch.
CREATE VIEW ... AS WITH ... SELECT ...; then a procedure with IN p_batch.
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Practice 10 of 10  •  Hard

Example 10: Sales analytics warehouse

● Hard💼 Real project: Data analyst portfolio project
A small star schema: a fact table of sales with date and product dimensions. Monthly growth with LAG and category totals with ROLLUP - the kind of report Power BI dashboards are built on.
ex10.sql
REAL RUN
✍ Try it yourself Explain the October jump: which product sold most in October? (Chhath and Diwali season!)
WHERE sale_date BETWEEN '2026-10-01' AND '2026-10-31' GROUP BY product ORDER BY SUM(amount) DESC
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Concept

Careers with SQL

RoleWhat you doAdd next
Data Analystreports, dashboards, answers business questions with SQLExcel, Power BI, Python pandas
Backend DeveloperAPIs and apps that read/write MySQLPHP/Laravel, Node.js or Python/Django
Database Administratorinstall, secure, back up, tune serversLinux, replication, cloud (HeatWave, RDS)
Data Engineerpipelines that move and clean dataPython, Airflow, cloud warehouses
ERP / MIS Executiveschool, hospital and business reportsTally, Excel, simple scripts
🎓

Next steps

Do 2-3 capstones, push them to GitHub, solve SQL practice problems daily (HackerRank, LeetCode SQL 50), and read the MySQL 9.7 Reference Manual for topics you liked.
🏆

Certifications

Oracle offers MySQL certifications for developers and administrators. Check the current exams on education.oracle.com before you prepare.
🤝

Internships and local work

Offer to build a database for a local school, clinic or shop. A real user and a real problem make the best portfolio story.
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Concept

Top 12 SQL interview questions (all covered in this course)

Q1. Difference between WHERE and HAVING?
Q2. INNER vs LEFT JOIN - with an example.
Q3. What is a primary key? A foreign key?
Q4. Explain 1NF, 2NF, 3NF.
Q5. Find the 2nd highest salary (3 ways).
Q6. RANK vs DENSE_RANK vs ROW_NUMBER.
Q7. What is an index? When does it NOT help?
Q8. What does ACID mean?
Q9. How do you prevent SQL injection?
Q10. DELETE vs TRUNCATE vs DROP.
Q11. How would you find a slow query?
Q12. What is a CTE? A recursive CTE?
PracticeAnswer each one aloud in 1 minute with an example from YOUR capstone project. Example for Q5: SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees);, DENSE_RANK(), or LIMIT 1 OFFSET 1.
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Check your understanding

Quick Quiz

Click an answer. Wrong answers shake; the right one turns green and explains why.

Q1. Best first step of a database project?
✔ Design first, code later (M12).
Q2. What should NOT be committed to GitHub?
✔ Use sample data and keep secrets in .env.
Q3. Which project shows window functions best?
✔ Rankings, growth and running totals need windows.
🎯
Your score: 0 / 3 (first try counts)
Answer all questions. Discuss any wrong answer with your partner before moving on.
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
M20Module summary

Recap: Capstone Projects & Career

What you learned in M20

  • ✔Plan: requirements → ER diagram → schema → data → queries.
  • ✔A capstone has schema.sql, seed.sql, queries.sql, programs, backup and README.
  • ✔Git + GitHub make your work visible to recruiters.
  • ✔Cloud MySQL, shared hosting or a VPS - with an app user and backups.
  • ✔SQL opens doors: analyst, backend developer, DBA, data engineer.
  • ✔Keep practising: one query a day keeps SQL sharp.
🏆

Module 20 complete!

You practised 10 real examples on a real MySQL server.

👉 Coming next

Your certificate: enter your name on the next slide and print it (Ctrl+P).
Complete MySQL Course  |  Part 5  |  Capstone Projects & Career
BRAINBIT INFOTECH, RANCHI
Certificate of Completion
This is to certify that
Click here and type your name
has successfully completed the Complete MySQL Course (Beginner to Advanced) - 20 modules, 200 practical examples and about 90 class hours, covering SQL:2023 with MySQL 9.7 LTS: queries, joins, window functions, database design, indexes, stored programs, transactions, JSON, security and real applications.
25 November 2026
Date
🐬
Nandan Kumar
Founder & Head of Training
1 / 1

✎ SQL Lab