MySQL Beginner
Relational Database Management System — structured schemas, ACID transactional standard, indexing architectures, and rapid relational querying.
Table of Contents
Database & Table Creation
Structured Query Language (SQL) coordinates relational engines. DDL commands like CREATE set up strict target containers, defining keys and relationship requirements early.
CREATE DATABASE project_db; USE project_db; CREATE TABLE users ( id INT AUTO_INCREMENT, username VARCHAR(50) NOT NULL, email VARCHAR(100) UNIQUE NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) );
Core Column Types
Fields require strict, upfront data allocation definitions to guarantee memory optimization and validate storage integrity across the storage engine blocks.
Data Manipulation (CRUD)
Data mutation operations utilize INSERT, UPDATE, and DELETE. These commands populate tables or alter record sets within safe transactional contexts.
-- 1. Create: Append values into targeted structural matrices INSERT INTO users (username, email) VALUES ('viduxsh', 'ivanvidux@gmail.com'); -- 2. Update: Modify existing records based on specific filters UPDATE users SET username = 'ivan_vidux' WHERE id = 1; -- 3. Delete: Purge matching rows instantly from database blocks DELETE FROM users WHERE id = 1;
Filtering with WHERE Clauses
Isolate and filter tracking metrics by using specific logic operators, string pattern match match mappings, and range boundaries inside your queries.
-- Extract records meeting advanced comparative parameters SELECT id, username, email FROM users WHERE created_at >= '2026-01-01 00:00:00' AND email LIKE '%@gmail.com' ORDER BY created_at DESC LIMIT 10;
Relational JOIN Operations
Relational databases avoid data duplication by splitting metrics across tables. Use JOIN operations to cleanly link related rows back together on shared key boundaries.
-- Correlate primary data fields and secondary structural vectors SELECT u.username, t.amount, t.category FROM users u INNER JOIN transactions t ON u.id = t.user_id WHERE t.status = 'verified';
Aggregation & Grouping
Condense multiple matching rows into a single summary block. Group records by shared attributes, and use HAVING statements to filter those combined sets.
SELECT category, SUM(amount) AS total_spent, COUNT(id) AS txn_count FROM transactions GROUP BY category HAVING total_spent > 500.00;
WHERE clause filters raw input data rows **before any groupings compile**, whereas HAVING filters calculated metrics **after group aggregations finalize**.
Subqueries & Nested Filters
You can embed queries inside other queries. This lets you construct dynamic criteria where a nested data search directly controls the main outer filter path.
-- Isolate user contexts whose ledger balances exceed global averages SELECT username, email FROM users WHERE id IN ( SELECT user_id FROM transactions WHERE amount > ( SELECT AVG(amount) FROM transactions ) );
Indexes & Performance Control
As tables scale up, looking up values sequentially can stall execution pipelines. Adding structural B-Tree **Indexes** lets the engine quickly map and locate records directly.
-- Generate specialized B-Tree indexing nodes over frequent search keys CREATE INDEX idx_transactions_user_date ON transactions (user_id, logged_at); -- Append EXPLAIN prefix ahead of a statement to review engine parsing footprints EXPLAIN SELECT * FROM transactions WHERE user_id = 42 AND logged_at > '2026-06-01';