What Is MySQL?
MySQL is one of the most popular open-source relational database servers. It stores data in tables, understands SQL, and powers a huge part of the web (WordPress, many online shops, and countless apps). It is owned by Oracle, and a community fork called MariaDB exists with similar commands.
| Fact | Detail |
|---|---|
| Type | Relational database management system (RDBMS) |
| Default engine | InnoDB (transactions, foreign keys, row locks) |
| Language | SQL, plus MySQL extras |
| Typical use | Web applications, shops, content systems, reporting |
| Versions in this course | MySQL 8.0 (the examples were run on 8.0.46) |
Client and Server
MySQL works in two parts. The server (mysqld) stores data and runs queries. A client connects to it over the network or a local socket and sends SQL. Examples of clients: the mysql command line program, MySQL Workbench, DBeaver, and your application code.
Installing MySQL
Choose the option that suits you. These commands are shown for reference and were not run in this lesson, because the practice server here was already installed.
| System | How |
|---|---|
| Ubuntu or Debian | sudo apt install mysql-server, then sudo mysql to log in as administrator |
| Windows or macOS | Download the MySQL Installer or the DMG from the official MySQL site, or use brew install mysql on macOS |
| Docker | docker run --name mysql -e MYSQL_ROOT_PASSWORD=secret -p 3306:3306 -d mysql:8.0 |
| Cloud | Managed MySQL from AWS RDS, Google Cloud SQL or Azure Database for MySQL |
root for applications. The security lesson later shows how to create limited users.
Connecting with the mysql Client
Inside the client, end every statement with ;. Type exit or press Ctrl+D to leave.
Your First Queries
SELECT can run without any table. Check the server version and the current database:
Result:
| greeting | sum_result |
|---|---|
| Hello, MySQL! | 5 |
The version differs on your machine. Our test server runs MySQL 8.0.46.
Useful SHOW Commands
| Command | Shows |
|---|---|
SHOW DATABASES; | All databases on the server |
USE shop; | Selects the database to work in |
SHOW TABLES; | Tables in the current database |
DESCRIBE customers; | Columns, types and keys of a table (also DESC) |
SHOW CREATE TABLE customers; | The exact CREATE TABLE statement |
SHOW VARIABLES LIKE 'version%'; | Server settings |
SHOW STATUS LIKE 'Threads%'; | Live server counters |
Now create the practice shop database from the first lesson of this course. Here is a look at a table in it:
Result:
| Tables_in_shop |
|---|
| customers |
| order_items |
| orders |
| products |
Result:
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| id | int | NO | PRI | NULL | (empty) |
| name | varchar(100) | NO | (empty) | NULL | (empty) |
| city | varchar(50) | YES | (empty) | NULL | (empty) |
| varchar(100) | YES | UNI | NULL | (empty) | |
| joined | date | NO | (empty) | NULL | (empty) |
The sql_mode Setting
sql_mode tells MySQL how strict to be. MySQL 8 enables strict modes by default, so bad data is rejected instead of silently changed.
Result:
| sql_mode |
|---|
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
| Mode | Effect |
|---|---|
STRICT_TRANS_TABLES | Reject invalid values (too long text, wrong type) with an error |
ONLY_FULL_GROUP_BY | Reject GROUP BY queries that select non-grouped columns |
NO_ZERO_DATE | Reject '0000-00-00' dates |
ERROR_FOR_DIVISION_BY_ZERO | Error on division by zero in data changes |
ERROR 1292: Incorrect date value: 'not-a-date' for column 'joined' at row 1
Comments and Case Rules
- Keywords are not case sensitive:
selectandSELECTare the same. - Table and database names are case sensitive on Linux, and not on Windows. Always use lowercase names to stay safe.
- Strings use single quotes:
'London'. Names with spaces or reserved words use backticks:order.
Common Beginner Mistakes
| Mistake | What happens | Fix |
|---|---|---|
| Forgetting the semicolon | The client waits for more input | End every statement with ; |
Running queries without USE database | Error: No database selected | Run USE shop; or prefix shop.customers |
| Using root in applications | A bug or attack can destroy everything | Create a limited user |
| Mixed-case table names | Works on Windows, fails on Linux | Use lowercase with underscores |
| Turning off strict mode | Bad data enters silently | Keep strict mode on |
Practice
- Run
SELECT VERSION();on your server. - List your databases and tables.
- Describe the
productstable and name its primary key. - Insert a row with an invalid date and read the error.
Conclusion
MySQL is a client-server relational database. Connect with the mysql client, use SHOW and DESCRIBE to explore, remember that MySQL 8 is strict by default, and keep names lowercase.

