What Is MySQL?
MySQL is an open-source relational database management system. Its first version was released in 1995; today it is developed by Oracle. It is one of the most widely used databases on websites and is most often mentioned together with PHP.
What is a database for?
Information on a site, such as articles, members, products or orders, must be stored in an orderly way and found quickly. A database keeps this information in tables. Each table consists of columns (fields) and rows (records). Tables can be linked to each other through shared fields; this is where the word "relational" comes from.
SQL: the language for talking to the database
You tell MySQL what to do with SQL (Structured Query Language):
CREATE TABLE pages (
id INT AUTO_INCREMENT PRIMARY KEY,
slug VARCHAR(100) NOT NULL UNIQUE,
title VARCHAR(200) NOT NULL,
body MEDIUMTEXT
) CHARACTER SET utf8mb4;
INSERT INTO pages (slug, title, body) VALUES ('linux', 'What Is Linux?', '...');
SELECT title, body FROM pages WHERE slug = 'linux';
UPDATE pages SET title = 'Linux' WHERE id = 1;
DELETE FROM pages WHERE id = 1;
Key features
- Fast and light: It scales from small sites to very busy systems.
- Widespread: It is available in almost every hosting package.
- InnoDB engine: Provides data integrity with transaction support and foreign keys.
- Full Unicode support: With the
utf8mb4character set, letters of every language and emojis are stored without problems.
MySQL and MariaDB
MariaDB is a database derived from the MySQL source code, started by MySQL's original developers. Its commands and usage are largely the same; many Linux distributions ship MariaDB by default.
For security
- Define a separate user for each site that can access only its own database; do not run the application as the database root user.
- Do not put user data directly into queries; use prepared statements.
- Do not expose the database to the internet; allow access only from the server itself.
- Take regular backups and practise restoring from them.
Read on: What Is PHP?