Aral Code

MySQL Tutorial

MySQL is one of the world's most popular databases. It's free, fast and reliable, and it powers WordPress, countless online shops, and many school, government and business systems in the Philippines. It's the "M" in the classic XAMPP and LAMP setups used with PHP.

This free course has 13 lessons. It focuses on what's specific to MySQL: setting up a real server, designing tables with the right types and keys, MySQL's built-in functions, views, stored procedures, user accounts and backups. Many queries can be run live on this page.

Before you start

Take our SQL course first, or at least its first ten lessons. This course assumes you know SELECT, WHERE, ORDER BY and basic joins.

What you'll be able to do

  • Install MySQL with XAMPP and use phpMyAdmin and the command line
  • Create databases and tables with proper data types and constraints
  • Link tables with primary and foreign keys
  • Use MySQL's string, number and date functions
  • Write views, stored procedures and transactions
  • Create users with limited permissions and back up your data
  • Design a complete enrollment database

All lessons

Getting Started

  1. Introduction to MySQLWhat MySQL is, how it relates to SQL, what a database server is, MySQL vs MariaDB, and where MySQL is used.
  2. Installing MySQL — XAMPP, phpMyAdmin and the Command LineRun MySQL with XAMPP, manage databases in phpMyAdmin, connect with the mysql command-line client, and know about MySQL Workbench.

Designing Databases

  1. MySQL Databases and Tables — CREATE, USE, SHOW and DESCRIBECreate and select databases with the right character set, create tables, inspect them with SHOW TABLES and DESCRIBE, and change or remove them with ALTER, DROP and TRUNCATE.
  2. MySQL Data Types — Choosing the Right TypeChoose MySQL data types for numbers (INT, TINYINT, DECIMAL), text (CHAR, VARCHAR, TEXT), dates (DATE, DATETIME, TIMESTAMP), booleans and ENUM, with Philippine examples.
  3. MySQL Keys — Primary Keys, Foreign Keys and IndexesLink tables with primary and foreign keys, use AUTO_INCREMENT, choose ON DELETE behavior, add UNIQUE constraints and indexes, and read EXPLAIN.

Working with Data

  1. MySQL CRUD — INSERT, SELECT, UPDATE and DELETECreate, read, update and delete rows in MySQL, insert many rows at once, use INSERT ... ON DUPLICATE KEY UPDATE, and protect your data with safe-update habits.
  2. MySQL String and Number FunctionsUse MySQL functions to format and clean data — CONCAT, UPPER, LOWER, LENGTH, SUBSTRING, LEFT, REPLACE, TRIM, LPAD, ROUND, FLOOR, CEIL, MOD, FORMAT, IF, IFNULL and CASE.
  3. MySQL Date and Time FunctionsWork with dates in MySQL — NOW, CURDATE, DATE_FORMAT, YEAR, MONTH, DAYNAME, DATEDIFF, DATE_ADD, TIMESTAMPDIFF for ages, and grouping sales by day and month.
  4. MySQL Joins and ReportsBuild real reports in MySQL by joining tables, grouping and summarizing — sales per customer, best sellers, class rankings with window functions, and WITH ROLLUP subtotals.

Advanced MySQL

  1. MySQL Views, Stored Procedures, Triggers and TransactionsSave queries as views, write stored procedures with parameters, react to changes with triggers, and keep related changes safe with START TRANSACTION, COMMIT and ROLLBACK.
  2. MySQL Users, Privileges and SecurityCreate MySQL user accounts, grant only the privileges an app needs, revoke access, change passwords, and follow basic database security practices.
  3. MySQL Backup and Restore — mysqldump, Export and ImportBack up MySQL databases with mysqldump and phpMyAdmin export, restore them with import, move a database to another computer or a web host, and import CSV data.
  4. MySQL Final Project — Design a School Enrollment DatabaseDesign and build a complete enrollment database in MySQL — plan the entities, create tables with keys and constraints, insert sample data, write report queries, add a view and a user.