FREE COURSE | BEGINNER
MySQL Fundamentals
Design relational databases and retrieve meaningful information using SQL.
Learning objectives
- Explain relational tables, keys and data types.
- Create and query a practice database.
- Modify records safely and combine related tables.
- Build a simple student enrollment database.
01. Introduction to MySQL
MySQL is a relational database management system. SQL is the language used to define, retrieve and modify data. Tables contain rows (records) and columns (attributes). A database server manages storage and access.
Editable SQL example
Original example output
Reveal expected output
result 5
Run edited SQL in your local MySQL client. This output is illustrative and assumes the stated setup.
Try it yourself
Explain the difference between SQL and MySQL.
02. Installation and Database Setup
Install MySQL Community Server and a client such as MySQL Workbench. Connect to your local server with your own credentials. Run the following statements in the SQL editor. Use a practice database, never production data.
Editable SQL example
Original example output
Reveal expected output
lnl_practice
Run edited SQL in your local MySQL client. This output is illustrative and assumes the stated setup.
Try it yourself
Create the practice database and verify the selected database.
03. Tables, Data Types and Keys
INT stores whole numbers; VARCHAR stores variable-length text. A primary key uniquely identifies a row. NOT NULL requires a value. Run this setup once in a fresh practice database.
Editable SQL example
Original example output
Reveal expected output
id | name | score 1 | Ana | 92 2 | Ben | 68 3 | Cara | 85
Run edited SQL in your local MySQL client. This output is illustrative and assumes the stated setup.
Try it yourself
Explain why two rows cannot share the same primary key.
04. INSERT and SELECT
INSERT adds records. SELECT retrieves chosen columns; an asterisk selects all columns. The examples from here use the students table from lesson 3. Run modification examples only once or restore the seed data.
Editable SQL example
Original example output
Reveal expected output
Ana | 92 Ben | 68 Cara | 85 Dani | 78
Run edited SQL in your local MySQL client. This output is illustrative and assumes the stated setup.
Try it yourself
Insert a fictional student with a unique ID.
05. Filtering and Sorting Records
WHERE filters rows before they are returned. AND combines conditions; OR accepts either condition. ORDER BY sorts results, and DESC reverses the default ascending order.
Editable SQL example
Original example output
Reveal expected output
Ana | 92 Cara | 85 Dani | 78 (if lesson 4 was run)
Run edited SQL in your local MySQL client. This output is illustrative and assumes the stated setup.
Try it yourself
Change the threshold to 90 and predict the result.
06. UPDATE and DELETE
UPDATE changes existing records; DELETE removes records. Always inspect the matching rows with SELECT before modifying them. Without WHERE, these statements can affect every row. Use a transaction to practice safely with InnoDB tables.
Editable SQL example
Original example output
Reveal expected output
1 | Ana | 92 2 | Ben | 75 3 | Cara | 85 Changes rolled back.
Run edited SQL in your local MySQL client. This output is illustrative and assumes the stated setup.
Try it yourself
Predict what happens if WHERE is omitted. Do not execute that variation.
07. Aggregate Functions and JOINs
COUNT counts rows; AVG calculates a mean. GROUP BY groups rows for aggregation. A JOIN combines related tables using matching keys. The following derived table demonstrates an inner join without changing data.
Editable SQL example
Original example output
Reveal expected output
Ana | Enrolled Count and average depend on whether lesson 4 was run.
Run edited SQL in your local MySQL client. This output is illustrative and assumes the stated setup.
Try it yourself
Try MIN(score) and MAX(score).
08. Interactive SQL Practice Lab
Predict which students meet a score threshold. The simulator below models SELECT, WHERE and ORDER BY on three fixed fictional records. It does not execute arbitrary SQL.
Editable SQL example
Original example output
Reveal expected output
Ana | 92 Cara | 85 (fixed lab dataset)
Run edited SQL in your local MySQL client. This output is illustrative and assumes the stated setup.
Try it yourself
Change the threshold and sort order in the simulator.
SQL query simulator
09. Mini Project: Student Records Database
Create related course and enrollment tables. Foreign keys protect relationships between records. Run this after lesson 3 in a fresh practice database. In applications, use parameterized queries, least-privilege accounts and server-side validation.
Editable SQL example
Original example output
Reveal expected output
Ana | MySQL
Run edited SQL in your local MySQL client. This output is illustrative and assumes the stated setup.
Try it yourself
Add a second enrollment and list all students enrolled in MySQL.