10. MySQL Part 1: Install, Create, Insert and SELECT
10.3 Creating Tables and Choosing Data Types
Table mhanje rows aani columns. Column banavtana tyacha data type nit nivda – chukicha type mhanje chukicha data aani kadhi kadhi security problem.
| Type | Stores | Example |
|---|---|---|
INT / BIGINT |
Whole numbers | id, age |
DECIMAL(10,2) |
Exact money values | fees |
VARCHAR(n) |
Text up to n characters | name VARCHAR(100) |
TEXT |
Long text | caption |
DATE / DATETIME / TIMESTAMP |
Dates and times | joined_on DATE |
BOOLEAN (TINYINT(1)) |
True/false | is_active |
ENUM('a','b') |
One of a fixed list | mode ENUM('online','offline') |
USE cybercourse;
CREATE TABLE students (
student_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(150) UNIQUE,
city VARCHAR(50) NOT NULL,
age INT,
fees_paid DECIMAL(10,2) DEFAULT 0,
joined_on DATE
);
CREATE TABLE courses (
course_id INT AUTO_INCREMENT PRIMARY KEY,
course_name VARCHAR(100) NOT NULL,
duration_wk INT
);
CREATE TABLE enrollments (
enroll_id INT AUTO_INCREMENT PRIMARY KEY,
student_id INT,
course_id INT,
score INT,
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (course_id) REFERENCES courses(course_id)
);
SHOW TABLES;
DESCRIBE students; -- or: DESC students;
SHOW CREATE TABLE students\G -- full definition
Ravindra Bagale's Tip
Many students create a VARCHAR(20) column for passwords – which means they plan to store plain passwords! Never store a password in plain text; hash it in PHP with password_hash() and store it in VARCHAR(255). Security starts from the table design itself.
Ravindra Bagale's Tip – मराठी
Password साठी VARCHAR(20) column बनवणारे बरेच students आहेत – म्हणजे ते plain password ठेवणार! Password कधी plain ठेवायचा नाही; PHP मध्ये password_hash() ने hash करून VARCHAR(255) मध्ये ठेवा. Table design पासूनच security सुरू होते.
Ravindra Bagale's Tip – हिंदी
बहुत से students password के लिए VARCHAR(20) column बनाते हैं – यानी वे plain password रखने वाले हैं! Password कभी plain मत रखो; PHP में password_hash() से hash करके VARCHAR(255) में रखो. Security table design से ही शुरू होती है.
Practice task
Create the three tables above and run DESCRIBE on each. Explain what AUTO_INCREMENT PRIMARY KEY and FOREIGN KEY do in your own words.
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.