10. MySQL Part 1: Install, Create, Insert and SELECT
10.4 Inserting Data
INSERT INTO students (name, email, city, age, fees_paid, joined_on) VALUES
('Ravindra Bagale', 'ravindra@example.com', 'Pune', NULL, 15000, '2026-01-05'),
('Shraddha Bagale', 'shraddha@example.com', 'Pune', 29, 15000, '2026-01-05'),
('Ruhi Bagale', 'ruhi@example.com', 'Nashik', 21, 12000, '2026-02-10'),
('Shahrukh', 'shahrukh@example.com', 'Nagpur', 24, 8000, '2026-02-15'),
('Amir', 'amir@example.com', 'Kolhapur', 26, 15000, '2026-03-01'),
('Salman', 'salman@example.com', 'Solapur', 23, 0, '2026-03-03'),
('Zoya', 'zoya@example.com', 'Sambhaji Nagar', 22, 10000, '2026-03-20'),
('Ravina', 'ravina@example.com', 'Nagpur', 25, 12000, '2026-04-02'),
('Raja', NULL, 'Nashik', 20, 5000, '2026-04-11'),
('Rani', 'rani@example.com', 'Pune', 27, 15000, '2026-04-18');
INSERT INTO courses (course_name, duration_wk) VALUES
('Networking', 4), ('Linux', 6), ('AWS', 8), ('Ethical Hacking', 10), ('SOC Analyst', 6), ('Cloud Security', 6);
INSERT INTO enrollments (student_id, course_id, score) VALUES
(1,1,92),(1,4,88),(2,2,79),(3,1,65),(3,2,71),(4,4,58),(5,3,84),
(6,1,45),(7,5,90),(8,4,76),(8,5,81),(10,3,67);
SELECT COUNT(*) FROM students; -- 10
Student 9 (Raja) is deliberately in no course, course 2 (Linux) has two students and course 6 (Cloud Security) has none – we will need these for JOINs. Ravindra's age is left NULL on purpose for the NULL examples.
Why this matters for security
Every INSERT built from user input must use prepared statements (section 9.7). A value like '), ('hacker','x inside a string-concatenated INSERT can add extra rows or break the query – that is SQL injection in an INSERT.
Ravindra Bagale's Tip
Many students write INSERT INTO students VALUES (...) without a column list – then when a column is added later, the query breaks. Always write the column names. And put text in single quotes, like 'Pune', and numbers without quotes.
Ravindra Bagale's Tip – मराठी
Column list शिवाय INSERT INTO students VALUES (...) लिहिणारे बरेच students आहेत – नंतर column वाढला की query तुटते. नेहमी column नावं लिहा. आणि text single quotes 'Pune' मध्ये, numbers quotes शिवाय.
Ravindra Bagale's Tip – हिंदी
बहुत से students column list के बिना INSERT INTO students VALUES (...) लिखते हैं – बाद में column बढ़ा तो query टूट जाती है. हमेशा column names लिखो. और text single quotes 'Pune' में, numbers बिना quotes के.
Practice task
Insert the sample data exactly as shown, then add yourself as a new student and one new course of your choice.
Extended teaching notes
Why this lesson matters
Use this lesson to strengthen systems you own: understand the risk, practise safely in a lab, then write and apply the fix.
Apply the fix across stacks
Same class of bug, same idea in every language.
Java / Spring Boot
Parameterise queries, encode output, CSRF tokens, limited Actuator, dependency scanning.
ASP.NET Core
EF Core / parameterised SQL, Razor encoding, HTTPS, Data Protection.
Node.js / Express
helmet, parameterised SQL, npm audit, avoid eval and shell concat.
Python / Django / Flask / FastAPI
ORM, autoescape, pip-audit, Bandit; never shell=True with user input.
PHP / Laravel
PDO/Eloquent, Blade escaping, composer audit.
Go / Ruby
database/sql placeholders / ActiveRecord; html/template / ERB escaping; govulncheck / Brakeman.
nginx / Apache / Tomcat
Hide versions, TLS, security headers, least-open ports.
MySQL / PostgreSQL / MongoDB / Redis
Private networks, auth on, least-privilege users, no 0.0.0.0/0.
AWS / Azure / GCP
Roles not long-lived keys, private data stores, cloud audit logs on.
Mini case study
Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.
Defender's worksheet (do this today)
- Write the lesson title, date and the exact lab target you are allowed to use.
- List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
- Run one safe check from the lesson on a lab system only. Paste the command and output.
- Write a two-sentence fix you would give a teammate.
- Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.
Indian workplace (sample data)
Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).
Global practice
Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.
Everyday analogy
Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.
Key terms
- Control: a safeguard (patch, config, process, detection).
- Finding: a weakness backed by evidence.
- Remediation: the fix plus how you verified it.
- Scope: systems you have written permission to touch.
- Least privilege: only the access the task needs.
- Defence in depth: several layers so one failure does not end the story.
Common mistakes
- Skipping written permission "just for a quick scan".
- Practising on hostel, office or public targets without authorisation.
- Collecting tool output without writing the fix.
- Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
- Publishing screenshots that contain secrets, cookies or internal hostnames.
Recap
- Evidence, fix, owner, date.
- Own lab only.
- Fix > spectacle.