Learn MySQL

MySQL is a free, open-source relational database management system that stores data in structured tables and lets you query it using SQL.

What Is MySQL?

MySQL is a relational database management system (RDBMS) that organizes data into tables made up of rows and columns, where each table typically represents one kind of entity such as customers, orders, or products, and relationships between tables are built using shared key columns. First released in 1995, MySQL is now owned by Oracle Corporation and is available under both an open-source GPL license and commercial licenses.

MySQL runs as a server process that listens for connections, usually on port 3306. Client programs, such as command-line tools, web applications, or admin panels, connect to the server, send SQL statements, and receive results back. This client-server model lets many applications and users share the same underlying data safely at the same time.

Why Developers Choose MySQL

  • Free and open source, with no licensing cost for most use cases
  • Extremely fast for the read-heavy workloads common in web applications
  • Runs on Windows, Linux, and macOS without any code changes
  • Huge ecosystem: works with PHP, Node.js, Python, Java, and virtually every framework
  • Backbone of the LAMP stack (Linux, Apache, MySQL, PHP) that powers millions of sites

Databases, Tables, and Rows

A single MySQL server can host many databases at once, each acting as an independent container for related tables. Inside a database, a table defines a fixed set of named columns, each with a data type such as INT, VARCHAR, or DATE, and every row you insert must fit that structure. This rigid structure is what makes relational databases predictable and reliable to query.

ColumnTypeDescription
customer_idINTUnique identifier for each customer
nameVARCHAR(100)Customer's full name
emailVARCHAR(150)Contact email address
countryVARCHAR(50)Customer's country of residence

Running Your First Queries

List all databases on the server

SHOW DATABASES;

Create and select a new database

CREATE DATABASE shopdb;
USE shopdb;

Create a simple table

CREATE TABLE customers (
  customer_id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100),
  email VARCHAR(150),
  country VARCHAR(50)
);
Note: Every SQL statement in MySQL ends with a semicolon (;). Forgetting it is the most common reason a query appears to 'hang' in the command-line client.
Note: Commands like DROP DATABASE and DROP TABLE delete data permanently with no undo. Always double-check which database you're connected to before running destructive statements.

Exercise: MySQL Introduction

What is MySQL primarily used for?

Frequently Asked Questions

What is the difference between MySQL and SQL?
SQL is the query language; MySQL is a database server that implements it. Learning SQL transfers to PostgreSQL or SQL Server, with each adding its own functions and syntax extensions.
Is MySQL free?
The Community Edition is free and open source under the GPL. Oracle also sells commercial editions with additional tooling and support, which is what most enterprise deployments pay for.
Should I use MySQL or PostgreSQL?
MySQL is simpler to run and very widely hosted. PostgreSQL has stricter standards compliance and richer types such as JSONB and arrays. For most new projects either works; PostgreSQL scales further in complexity.