Downloads

MySQL Introduction Ebook

Learn MySQL fundamentals with a beginner-friendly, self-paced ebook covering databases, tables, SQL, CRUD, joins, backups, and safe database practices. Available for $4.99.

MySQL Introduction Ebook

This introductory MySQL ebook is a self-paced learning resource for complete beginners, students, and web developers who need a practical foundation in relational databases. You do not need previous SQL or database experience. Basic computer use and familiarity with structured information, such as spreadsheet rows and columns, are helpful.

By the end, you should understand how MySQL stores structured information, create a small database, design tables, write core SQL queries, work with related tables, summarize data, and use safer habits when changing or backing up records.

Item: Format — Value: Downloadable ebook

Item: Skill level — Value: Beginner

Item: Subject — Value: MySQL and relational database fundamentals

Item: Price — Value: $4.99

Item: Purchase availability — Value: Available to purchase

Purchase the MySQL Introduction Ebook for $4.99. After selecting the purchase action and completing checkout, confirm that the item appears in your cart or that the checkout page identifies the MySQL Introduction Ebook before paying.

What Is MySQL?

MySQL is a relational database management system, often abbreviated as RDBMS. It stores organized information and provides tools for defining, querying, changing, securing, and backing up that information.

A database is an organized collection of related data. In MySQL, a database commonly contains tables. A table stores records in rows and fields in columns:

  • A row is one record, such as one contact or one product.
  • A column is an attribute or field, such as a name, price, or creation date.
  • A column has a name and a data type that describes the values it can store.
  • A relationship connects records in different tables, such as an order belonging to a customer.

SQL means Structured Query Language. SQL is the language used to define relational structures, query data, and modify records. MySQL is the database system that receives and executes SQL statements. In other words, SQL is the language; MySQL is one system that implements and runs that language.

Important database terms

  • Primary key: A column, or group of columns, that uniquely identifies each row in a table.
  • Foreign key: A column that references a key in another table and represents a relationship.
  • Query: A SQL statement that requests, changes, or defines database information.
  • CRUD: Create, read, update, and delete—the four basic data operations.
  • JOIN: A query operation that combines related data from multiple tables.
  • Index: A database structure that can improve lookup and query performance, usually at the cost of additional storage and write work.

Getting Started with a MySQL Environment

You can install MySQL on your computer or use an existing server supplied by a hosting provider, classroom, or development environment. A local installation is useful for practice because it lets you create test databases without changing production data.

To work with MySQL, you need a running MySQL server and an account with suitable permissions. You can connect through the MySQL command-line client or through a graphical administration tool. A graphical tool generally provides a query editor, database and table browser, and result grid. The command line is valuable because it makes SQL statements and error messages visible and repeatable.

Create and select a practice database

Once connected, create a dedicated practice database and select it before creating tables:

CREATE DATABASE learning_mysql;
USE learning_mysql;

CREATE DATABASE creates the database. USE selects it as the default database for subsequent statements in the current session. Selecting the wrong database is a common cause of “table not found” errors.

Create a contacts table

This example creates a simple contacts table with an automatically generated identifier, a required name, a unique email address, and a default creation timestamp:

CREATE TABLE contacts (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(255) UNIQUE,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

NOT NULL requires a value. UNIQUE prevents duplicate non-null values. AUTO_INCREMENT lets MySQL generate a new numeric identifier, and PRIMARY KEY makes that identifier unique for each row.

Database and Table Design Basics

Good design begins by identifying the things your application needs to store. Each kind of thing often becomes a table: customers, products, orders, or contacts. Columns then describe each thing. Avoid placing unrelated repeating information in one large table when separate related tables would make the data clearer and more consistent.

Common MySQL data types

Data type: INT — Use case: Whole numbers and identifiers — Example: 42

Data type: VARCHAR — Use case: Short variable-length text — Example: 'Ava Lee'

Data type: TEXT — Use case: Longer text — Example: A product description

Data type: DECIMAL — Use case: Exact numeric values such as prices — Example: 19.95

Data type: DATE — Use case: Calendar dates — Example: 2026-08-18

Data type: DATETIME — Use case: Date and time values — Example: 2026-08-18 14:30:00

Data type: BOOLEAN — Use case: True or false states — Example: TRUE

Choose a type that matches the meaning of the value. Use DECIMAL for monetary values rather than floating-point types when exact decimal arithmetic matters. Choose a suitable maximum length for VARCHAR, and use dates or date-times instead of storing dates as arbitrary text.

Keys, constraints, defaults, and relationships

A primary key gives every row a stable identity. Required fields, uniqueness rules, valid ranges, and foreign keys are examples of constraints. Constraints help enforce data integrity, meaning that stored data remains accurate, consistent, and connected according to the rules of the application.

A foreign key connects a child table to a parent table. For example, an order can contain a customer_id that references customers.id. This prevents an order from referring to a customer that does not exist, when the constraint is configured and enforced.

Table: customers — Key field: customer_id — Relationship: Referenced by orders — Purpose: Store customer information

Table: orders — Key field: order_id; customer_id — Relationship: Each order belongs to a customer — Purpose: Store order headers

Table: order_items — Key field: order_item_id; order_id; product_id — Relationship: Connect orders and products — Purpose: Store products and quantities within orders

Table: products — Key field: product_id — Relationship: Referenced by order_items — Purpose: Store product details

This structure supports a many-to-many relationship between orders and products: one order can contain many products, and one product can appear in many orders. The order_items table stores the connection and details such as quantity and sale price.

Core SQL Data Operations

The CRUD cycle is the foundation of everyday database work. SQL statements should be tested against practice data before they are used on important records.

INSERT: add records

INSERT INTO contacts (name, email)
VALUES ('Ava Lee', 'ava@example.com');

Name the target columns explicitly. This makes the statement easier to read and less sensitive to changes in the table's column order.

SELECT: read records

SELECT id, name, email
FROM contacts
WHERE name LIKE 'A%'
ORDER BY name;

This query selects only the requested columns, filters names beginning with “A,” and sorts the result alphabetically. Use * only when you genuinely need every column; selecting specific columns reduces clutter and can reduce unnecessary data transfer.

Filter, sort, and limit results

SELECT name, email
FROM contacts
WHERE email IS NOT NULL
ORDER BY name ASC
LIMIT 10;

WHERE filters rows. Common logical operators include AND, OR, and NOT. Use parentheses when combining conditions so the intended logic is clear. ORDER BY sorts results, and LIMIT restricts how many rows are returned.

UPDATE: change records

UPDATE contacts
SET email = 'ava.lee@example.com'
WHERE id = 1;

The SET clause specifies the new value. The WHERE clause identifies the rows to change.

DELETE: remove records

DELETE FROM contacts
WHERE id = 1;

Deleting a row is often irreversible unless you have a backup or transaction that can be rolled back. Always inspect the target rows before executing a destructive statement.

Querying Related and Summarized Data

Aliases, logical conditions, and aggregates

An alias gives a column or table a temporary name in a query. Aggregate functions calculate one result from multiple rows:

  • COUNT counts rows or non-null values.
  • SUM adds numeric values.
  • AVG calculates an average.
  • MIN returns the smallest value.
  • MAX returns the largest value.
SELECT product_id,
       COUNT(*) AS line_count,
       SUM(quantity * unit_price) AS product_sales,
       AVG(unit_price) AS average_price
FROM order_items
GROUP BY product_id
HAVING SUM(quantity * unit_price) > 100
ORDER BY product_sales DESC;

GROUP BY creates one group for each product. HAVING filters groups after aggregation, while WHERE filters individual rows before grouping. This query calculates sales totals and keeps only products whose grouped sales exceed 100.

JOIN related tables

A join combines rows using related columns. An inner join returns records with a match in both tables:

SELECT o.order_id,
       c.name AS customer_name,
       o.order_date
FROM orders AS o
JOIN customers AS c
  ON c.customer_id = o.customer_id
ORDER BY o.order_date DESC;

Use a left join when you want every row from the left table even if a related row is missing:

SELECT c.customer_id,
       c.name,
       o.order_id
FROM customers AS c
LEFT JOIN orders AS o
  ON o.customer_id = c.customer_id;

One-to-many relationships can produce multiple result rows. A customer with five orders appears in five joined rows. If a join returns missing or duplicated data, check the key fields, the join condition, and the level of detail you intend to display.

SQL Command Reference

Command: CREATE DATABASE — Purpose: Create a database — Typical use: Start a new schema

Command: CREATE TABLE — Purpose: Define a table — Typical use: Add columns, keys, and constraints

Command: INSERT — Purpose: Add rows — Typical use: Store new records

Command: SELECT — Purpose: Read rows — Typical use: Display or analyze data

Command: UPDATE — Purpose: Change rows — Typical use: Correct or maintain records

Command: DELETE — Purpose: Remove rows — Typical use: Delete obsolete records

Command: ALTER TABLE — Purpose: Change a table definition — Typical use: Add a column or constraint

Command: DROP TABLE — Purpose: Remove a table and its data — Typical use: Delete an unwanted practice table

Practical Learning Projects

Contacts database

Create the learning_mysql database and contacts table shown above. Insert several contacts, find names beginning with a particular letter, update one email address, and remove a test record. This project introduces the full CRUD cycle.

Product inventory

Create a products table with an identifier, name, price, quantity, and an availability flag. Insert products, select items where quantity is greater than zero, update a price or quantity, and delete a discontinued test product. Use DECIMAL for prices and a precise WHERE clause for each change.

Customers and orders

Create customers, orders, products, and order_items tables. Use primary keys for each table and foreign keys for the references. Join orders to customers to display order information together with customer names.

Sales summary

Use COUNT, SUM, and AVG with GROUP BY to calculate sales by product or customer. Sort the grouped results by a calculated total and use HAVING to keep only groups meeting a threshold.

Perform a guarded update

Before changing a record, run an equivalent SELECT with the same condition. Confirm that the returned rows are exactly the intended targets. Then execute the UPDATE with a precise predicate. For critical changes, learn to use transactions so changes can be reviewed and rolled back before they are committed.

Safe and Maintainable MySQL Use

  • Never omit WHERE from an UPDATE or DELETE unless changing or removing every row is intentional.
  • Test the predicate with SELECT first and check the affected-row count afterward.
  • Use primary keys, foreign keys, required fields, unique constraints, and appropriate data types to protect data integrity.
  • Keep regular exports or backups and test that restoration works.
  • Do not place database passwords directly in application source code or commit them to a source-control repository. Use protected configuration such as environment variables or a secrets manager.
  • Applications should use parameterized queries or prepared statements rather than concatenating untrusted input into SQL.
  • Add indexes deliberately. An index can speed up lookups and joins, but too many indexes increase storage use and can slow inserts and updates.

Export and restore awareness

The mysqldump utility can export a database into a SQL file:

mysqldump -u username -p learning_mysql > learning_mysql.sql

After entering the password when prompted, the file can be restored with the MySQL client:

mysql -u username -p learning_mysql < learning_mysql.sql

Backups should be stored securely, protected from unauthorized access, and periodically tested. A backup that has never been restored is not yet verified as a reliable recovery plan.

Troubleshooting Common Problems

Unable to connect to MySQL

Check whether the MySQL server is running. Then verify the host, port, username, and password. The account may also lack permission to connect from the requested host or to access the selected database. Confirm service status, connection settings, and user privileges.

Unknown database or table

The database may not have been created, the wrong database may be selected, or the table name may be misspelled. List available databases and tables, select the intended database with USE, and check identifier spelling and letter casing.

Duplicate entry

This error usually means that a value conflicts with a primary key or unique constraint. Inspect existing records. Decide whether to insert a new value, update the existing row, or revise the constraint based on the actual data rule.

UPDATE or DELETE affected too many rows

A missing or overly broad WHERE clause is the usual cause. Stop and inspect the affected data if possible. Run an equivalent SELECT, narrow the predicate, and use a transaction for critical operations.

Join results are missing or duplicated

Review the primary-key and foreign-key fields and verify the join predicate. An inner join excludes unmatched records, while a one-to-many relationship naturally produces multiple rows for one parent. Choose the join type and result granularity that match the question you are asking.

Next Steps After the Ebook

Once the fundamentals are comfortable, continue with database normalization, MySQL user accounts and privileges, indexes and query optimization, transactions and ACID concepts, backup and recovery, and application connectivity from PHP, Python, Java, or Node.js. Advanced SQL topics include subqueries, views, and stored procedures. Secure application development should also cover SQL injection prevention and prepared statements.

Get the MySQL Introduction Ebook for $4.99 and study the examples at your own pace. After adding it, verify the cart confirmation before proceeding to checkout.