Customer Service 1-800-221-5528

Murach’s MySQL (4th Edition)

by Joel Murach
20 chapters, 652 pages, 267 figures
Published Novermber 2023
ISBN 978-1-943873-10-4
List price: $59.50

The fourth edition of our best-selling MySQL book works better than ever for teaching SQL and database design. We’ve carefully checked and updated every example so your students will be getting the best possible learning experience. Regardless of prior skill level, they’ll appreciate the real-world examples, easy-to-understand instructions, and meaningful assignments.

A complete set of instructor’s materials is available for this book so you can spend your time teaching, not prepping. Request your review copy today and see why Murach’s MySQL is an enduring staple in programming classrooms.

Now available as a Canvas course!

The Canvas course file contains all the objectives, quizzes, assignments, and slides that you need to run an effective course. It only takes a few clicks to import it into the Canvas LMS. Then, you can customize it for your course. Learn more.

Comprehensive, exceptionally organized and presented, and a ‘must-have’ guide for anyone who works with MySQL, beginning and experienced developers alike, […] Murach’s MySQL is an ideal curriculum textbook for school, community, and academic library Computer Software collections, and an enduringly valued reference of all MySQL users."

James Cox, Midwest Book Review

  • About this Book
  • Table of Contents
  • Courseware
  • FAQs
  • Corrections

Book description

Section 1: An introduction to SQL

This section presents a solid foundation in SQL skills. It starts by presenting the concepts and terms for working with any database. Then, it shows how to code and run the basic SQL statements for retrieving, adding, updating, and deleting data in a MySQL database. When your students complete this section, they’ll be ready to continue with any of the other sections in the book.

Section 2: More SQL skills as you need them

This section presents advanced SQL skills for retrieving data from a database. That includes working with summary queries, subqueries, data types, and functions. These chapters are modular, so you can teach them in whatever sequence you prefer.

Section 3: Database design and implementation

This section shows how to design a database and how to implement that design by using either SQL statements or MySQL Workbench. When your students are done, they’ll be able to design and implement their own databases. In addition, this section shows how to create and use views to simplify data access and improve data security.

Section 4: Stored program development

This section takes your students from good MySQL programmers to great ones by teaching them how to create stored programs. Here, they’ll learn how to create stored procedures that use MySQL’s procedural language to manage transactions and locking. In addition, they’ll learn how to create user-defined functions, triggers, and events.

Section 5: Database administration

In this section, your students will learn a starting set of skills for becoming a database administrator (DBA). First, they’ll learn how to secure, back up, and restore a MySQL database that’s running on a local server. Then, they’ll learn how to perform most of the same skills on a MySQL database that’s running remotely on Amazon’s cloud computing platform, AWS.

Book features

Here are three features of this book that will help your students learn faster and better.

It starts by showing how to query a database

Murach’s MySQL starts by showing how to query an existing database rather than showing how to create a new database. Why?

First, it’s motivating for your students to see results right away, and querying provides immediate results with just a single line of code. Second, querying an existing database helps your students gain insight into the decisions that have to be made when designing a database. As a result, learning how to query a database now makes it easier for students to learn how to design a database later.

It shows how to use MySQL Workbench

This book doesn’t assume that your students have any prior knowledge about the tools for working with a MySQL database. As a result, it recommends using MySQL Workbench because we think that’s the best tool available for working with a MySQL database. In addition, this book explains how to use Workbench as thoroughly as it explains how to write SQL statements.

It presents hundreds of real-world examples

This book contains hundreds of example SQL statements that range from the simple to the complex, and every one of them is included in the download for this book. That way, your students can quickly get the idea of how a feature works from the simple examples and also see how the feature works in the real world from the complex ones.

What's new in this edition

  • We added a new chapter on hosting a MySQL database in the cloud using Amazon Web Services (AWS)
  • We streamlined chapters 1 and 2 to help your students get started more quickly.
  • We streamlined chapter 19 to help your students learn how to backup and restore databases more easily.
  • We updated this book to MySQL 8.0.34, removing deprecated data types and functions and adding new statement options and clauses.

What courses this book can be used for

  • As the main text for any SQL course.
  • As a supplementary text for a traditional database course.

What software your students need

Although you can use this book with most versions of MySQL, we recommend that you use:

  • MySQL Community Server 8.0 or higher
  • MySQL Workbench 8.0 or higher

This software can be downloaded for free from MySQL’s website, and appendixes A (Windows) and B (macOS) provide complete instructions for downloading and installing it.

What people say about this book

"This book was the text in my Database Concepts class, and I am so thankful that it was! It provided excellent explanations and examples of database syntax, queries, subqueries, design, etc. It spent sufficient time breaking down difficult topics into the basic elements and then built off of those concepts to bring everything together. The book was reasonably priced too! I aced the class and decided to take more database classes because of this book."
- Posted at an online bookseller

"This is a fantastic book! It has more info than books at twice the cost, but it presents that info in a concise, digestible manner. I wish I had a resource like this when I was first starting with MySQL."
- Eric Chernoff, Team Leader, Cisco Systems

"I like this style of presentation; it’s not chatty and discursive, but it covers the material in a detailed way with good examples that you can refer to without wading through descriptions."
- Sue Gee, (Kay Ewbank) I Programmer

"I was amazed at how much information was packed into this book. The style of the book made it really easy to read and understand the information.”
- Paul Turpin, Southeastern Inter-Relational Database Users Group

"One thing I enjoyed is that the book is well-indexed, and the material itself is concise, with stand-alone, real-world examples. It’s not theoretical, it’s practical, and presents topics in a friendly style that can be consumed painlessly."
- Posted at an online bookseller

"If you ever want to learn to use MySQL, write SQL queries, create database elements, then this is the book to pick up. Rating: 10 Horseshoes."
- Review by Mohamed Sanaulla, JavaRanch.com

View the table of contents for this book in a PDF: Table of Contents (PDF)

Click on any chapter title to display or hide its content.

Section 1 An introduction to MySQL

Chapter 1 An introduction to relational databases

An introduction to client/server systems

The hardware components of a client/server system

The software components of a client/server system

Other client/server architectures

An introduction to the relational database model

How a table is organized

How tables are related

How columns are defined

How to read a database diagram

An introduction to SQL and SQL-based systems

A brief history of SQL

A comparison of four relational databases

The SQL statements

An introduction to the SQL statements

How to work with database objects

How to query a single table

How to join data from two or more tables

How to add, update, and delete data in a table

SQL coding guidelines

Chapter 2 How to use MySQL Workbench and other development tools

An introduction to MySQL Workbench

The Home page of MySQL Workbench

How to open a database connection

How to view the status of the database server

How to navigate through the database objects

How to view and edit the data for a table

How to view and edit the column definitions for a table

How to use MySQL Workbench to run SQL statements

How to enter and execute a SQL statement

How to handle syntax errors

How to open and save SQL scripts

How to enter and execute SQL scripts

How to use the MySQL Reference Manual

How to view the manual

How to look up information

How to use the MySQL Command Line Client

How to start and stop the MySQL Command Line Client

How to use the MySQL Command Line Client to work with a database

Chapter 3 How to retrieve data from a single table

An introduction to the SELECT statement

The basic syntax of the SELECT statement

SELECT statement examples

How to code the SELECT clause

How to code column specifications

How to name the columns in a result set using aliases

How to code arithmetic expressions

How to use the CONCAT function to join strings

How to use functions with strings, dates, and numbers

How to test expressions by coding statements without FROM clauses

How to eliminate duplicate rows

How to code the WHERE clause

How to use the comparison operators

How to use the AND, OR, and NOT logical operators

How to use the IN operator

How to use the BETWEEN operator

How to use the LIKE and REGEXP operators

How to use the IS NULL clause

How to code the ORDER BY clause

How to sort by a column name

How to sort by an alias, expression, or column number

How to code the LIMIT clause

How to limit the number of rows

How to return a range of rows

Chapter 4 How to retrieve data from two or more tables

How to work with inner joins

How to code an inner join

How to use table aliases

How to join to a table in another database

How to use compound join conditions

How to use a self-join

How to join more than two tables

How to use the implicit inner join syntax

How to work with outer joins

How to code an outer join

Outer join examples

Other skills for working with joins

How to join tables with the USING keyword

How to join tables with the NATURAL keyword

How to use cross joins

How to work with unions

How to code a union

A union that combines result sets from different tables

A union that combines result sets from the same tables

A union that simulates a full outer join

Chapter 5 How to insert, update, and delete data

How to create test tables

How to create the tables for this book

How to create a copy of a table

How to insert new rows

How to insert a single row

How to insert multiple rows

How to insert default values and null values

How to use a subquery in an INSERT statement

How to update existing rows

How to update rows

How to use a subquery in an UPDATE statement

How to delete existing rows

How to delete rows

How to use a subquery in a DELETE statement

Section 2 More SQL skills as you need them

Chapter 6 How to code summary queries

How to work with aggregate functions

How to code aggregate functions

Queries that use aggregate functions

How to group and summarize data

How to code the GROUP BY and HAVING clauses

Queries that use the GROUP BY and HAVING clauses

How the HAVING clause compares to the WHERE clause

How to code compound search conditions

How to use the WITH ROLLUP operator

How to use the GROUPING function

How to code aggregate window functions

How the aggregate window functions work

How to use frames

How to use named windows

Chapter 7  How to code subqueries

An introduction to subqueries

Where to code subqueries

When to use subqueries

How to code subqueries in the WHERE clause

How to use the IN operator

How to use the comparison operators

How to use the ALL keyword

How to use the ANY and SOME keywords

How to code correlated subqueries

How to use the EXISTS operator

How to code subqueries in other clauses

How to code subqueries in the HAVING clause

How to code subqueries in the SELECT clause

How to code subqueries in the FROM clause

How to work with complex queries

A complex query that uses subqueries

A procedure for building complex queries

How to work with common table expressions

How to code a CTE

How to code a recursive CTE

Chapter 8  How to work with data types

The data types

Overview

The character types

The integer types

The fixed-point and floating-point types

The date and time types

The ENUM and SET types

The binary types

The large object types

How to convert data

How implicit data conversion works

How to convert data using the CAST and CONVERT functions

How to convert data using the FORMAT and CHAR functions

Chapter 9 How to use functions

How to work with string data

A summary of the string functions

Examples that use string functions

How to sort by a string column that contains numbers

How to parse a string

How to work with numeric data

How to use the numeric functions

How to search for floating-point numbers

How to work with date/time data

How to get the current date and time

How to parse dates and times with date/time functions

How to parse dates and times with the EXTRACT function

How to format dates and times

How to perform calculations on dates and times

How to search for a date

How to search for a time

Other functions you should know about

How to use the CASE function

How to use the IF, IFNULL, and COALESCE functions

How to use the regular expression functions

How to use the ranking functions

How to use the analytic functions

Section 3 Database design and implementation

Chapter 10 How to design a database

How to design a data structure

The basic steps for designing a data structure

How to identify the data elements

How to subdivide the data elements

How to identify the tables and assign columns

How to identify the primary and foreign keys

How to enforce the relationships between tables

How normalization works

How to identify the columns to be indexed

How to normalize a data structure

The seven normal forms

How to apply the first normal form

How to apply the second normal form

How to apply the third normal form

When and how to denormalize a data structure

How to use MySQL Workbench for database design

How to open an existing EER model

How to create a new EER model

How to work with an EER model

How to work with an EER diagram

Chapter 11 How to create databases, tables, and indexes

How to work with databases

How to create and drop a database

How to select a database

How to work with tables

How to create a table

How to code a primary key constraint

How to code a foreign key constraint

How to alter the columns of a table

How to alter the constraints of a table

How to rename, truncate, and drop a table

How to work with indexes

How to create an index

How to drop an index

A script that creates a database

How to use MySQL Workbench

How to work with the columns of a table

How to work with the indexes of a table

How to work with the foreign keys of a table

How to work with character sets and collations

An introduction to character sets and collations

How to view character sets and collations

How to specify a character set and a collation

How to work with storage engines

An introduction to storage engines

How to view storage engines

How to specify a storage engine

Chapter 12 How to create views

An introduction to views

How views work

Benefits of using views

How to work with views

How to create a view

How to create an updatable view

How to use the WITH CHECK OPTION clause

How to insert or delete rows through a view

How to alter or drop a view

Section 4 Stored program development

Chapter 13 Language skills for writing stored programs

An introduction to stored programs

Four types of stored programs

A script that creates and calls a stored procedure

A summary of statements for coding stored programs

How to write procedural code

How to display data

How to declare and set variables

How to code IF statements

How to code CASE statements

How to code loops

How to use a cursor

How to declare a condition handler

How to use a condition handler

How to use multiple condition handlers

Chapter 14 How to use transactions and locking

How to work with transactions

How to commit and rollback transactions

How to work with save points

How to work with concurrency and locking

How concurrency and locking are related

The four concurrency problems that locks can prevent

How to set the transaction isolation level

How to lock selected rows

How to prevent deadlocks

Chapter 15 How to create stored procedures and functions

How to code stored procedures

How to create and call a stored procedure

How to code input and output parameters

How to set a default value for a parameter

How to validate parameters and raise errors

A stored procedure that inserts a row

How to work with user variables

How to work with prepared statements

How to drop a stored procedure

How to code stored functions

How to create and call a function

How to use function characteristics

A function that calculates balance due

How to drop a function

How to use Workbench with procedures and functions

How to view and edit stored routines

How to create stored routines

How to drop stored routines

Chapter 16 How to create triggers and events

How to work with triggers

How to create a BEFORE trigger

How to use a trigger to enforce data consistency

How to create an AFTER trigger

How to view or drop triggers

How to work with events

How to turn the event scheduler on or off

How to create an event

How to view, alter, or drop events

Section 5 Database administration

Chapter 17 An introduction to database administration

Database administration concepts

Database administrator responsibilities

Types of database files

Types of log files

How to monitor the server

How to view the server status

How to view and kill processes

How to view the status variables

How to view the system variables

How to configure the server

How to set system variables using MySQL Workbench

How to set system variables using a text editor

How to set system variables using the SET statement

How to work with logging

How to enable and disable logging

How to configure logging

How to view text-based logs

How to manage logs

Chapter 18 How to secure a database

An introduction to user accounts

An introduction to SQL statements for user accounts

A summary of privileges

The four privilege levels

The grant tables in the mysql database

How to work with users and privileges

How to create, rename, and drop users

How to specify user account names

How to grant privileges

How to view privileges

How to revoke privileges

How to change passwords

A script that creates users

How to work with roles

How to create, manage, and drop roles

A script that creates users and roles

How to use MySQL Workbench

How to work with users and privileges

How to connect as a user for testing

Chapter 19 How to backup and restore a database

How to back up and restore a database

Strategies for backing up and restoring databases

How to use Workbench to create a full backup

How to use Workbench to restore a full backup

How to execute statements in the binary log

How to use Workbench to export and import data

How to export data to a file

How to import data from a file

Chapter 20 How to host a database with AWS

How to create and configure a MySQL RDS instance

The AWS Management Console

The Amazon RDS Databases page

How to create a MySQL RDS instance

How to modify an RDS instance so it’s publicly accessible

How to add a firewall rule for your IP address

How to use MySQL Workbench with an RDS instance

How to connect to an RDS instance

How to run scripts and SQL statements against an RDS database

How to backup and restore a database instance

How to work with the built-in backup

How to create a backup plan

How to work with snapshots

How to restore a database instance

More skills for working with RDS

How to check the AWS Billing Dashboard

How to delete an RDS database

Appendices

Appendix A How to set up Windows for this book

How to install MySQL Community Server

How to start and stop the MySQL sever

How to install MySQL Workbench

How to download the files for this book

How to create the databases for this book

How to restore the databases

Appendix B How to set up macOS for this book

How to install MySQL Community Server

How to start and stop the MySQL sever

How to install MySQL Workbench

How to download the files for this book

How to create the databases for this book

How to restore the databases

The instructor’s materials that you can request from this site provide everything you need for an effective course.

Objectives

  • Help your students focus on the skills that they should master.

Test banks

  • Provide a way to test comprehension.
  • Can be imported to all modern LMSs.
  • Are designed to test the skills described by the objectives for each chapter.
  • Use only multiple-choice test questions because they have the highest validity.

Extra exercises

  • Give your students a chance to gain valuable hands-on experience.
  • Can be used for assessing coding skills since the solutions aren’t available to students (unlike the exercises that are printed in the book).

PowerPoint slides

  • Summarize the critical information presented in the book.
  • Start with the instructional objectives for each chapter.

For a detailed description of all the materials, please see the Instructor’s Summary PDF. And if you use the Canvas LMS, we also provide a Canvas course file that you can use to import all of these materials with just a few clicks.

On this page, we’ll be posting answers to the questions that come up most often about this book. So if you have any questions that you haven’t found answered here at our site, please email us. Thanks!

There are no book corrections that we know of at this time. But if you find any, please email us, and we’ll post any corrections that affect the technical accuracy of the book here. Thank you!

Murach college books and courseware since 1974