MySQL

The dependable workhorse on nearly every shared host.

What is it?

MySQL is one of the world's most widely deployed relational databases. It stores data in tables, speaks SQL, and has been the "M" in the classic LAMP stack (Linux, Apache, MySQL, PHP) for decades - which is why it comes pre-installed on virtually every shared hosting plan, usually with the phpMyAdmin web interface for managing it.

It's rock-solid, fast for the read-heavy workloads typical of websites, and so common that nearly every tutorial, CMS, and hosting panel assumes it.


When to use it

MySQL is the natural pick on shared hosting - it's already there, already configured, and pairs perfectly with PHP. It handles structured data (users, products, posts) extremely well and is a great first "real" database because the SQL you learn transfers everywhere. For zero-setup local learning, SQLite is even simpler; for feature depth and large-scale growth, PostgreSQL has the edge.


Core concepts

  • Databases and tables - a MySQL server hosts multiple databases; each database holds tables with typed columns (VARCHAR, INT, DATETIME…).
  • Users and privileges - apps connect with a username/password that's granted access to a specific database. Hosting panels create these for you.
  • AUTO_INCREMENT keys - the standard way to give every row a unique id automatically.
  • Storage engine (InnoDB) - the modern default; it gives you transactions and foreign keys. You rarely change it, but it's good to know the name.
  • phpMyAdmin - the browser-based admin tool on most shared hosts: create tables, browse rows, and run queries without touching a terminal.

A taste of the code

CREATE TABLE guestbook (
  id         INT AUTO_INCREMENT PRIMARY KEY,
  author     VARCHAR(100) NOT NULL,
  message    TEXT NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO guestbook (author, message)
VALUES ('Sam', 'First post!');

SELECT author, message FROM guestbook
ORDER BY created_at DESC;

Standard SQL - create a table, add a row, read it back. This exact pattern is behind most contact forms and comment sections on the web.


Your first steps

  1. Learn SQL basics - they're 90% of using MySQL.
  2. Get MySQL running: on a shared host it's one click in the control panel; locally, XAMPP bundles MySQL with PHP and phpMyAdmin.
  3. Open phpMyAdmin, create a database and a table, and insert a few rows through the interface.
  4. Connect from code - PDO in PHP or mysql2 in Node.js - using prepared statements for any user input.
  5. Build a guestbook or blog: a form that inserts rows and a page that lists them.

Common beginner mistakes

  • Using utf8 instead of utf8mb4. MySQL's legacy utf8 can't store emoji and some other characters. Use utf8mb4 for databases, tables and connections.
  • Connecting as root (or one all-powerful user) from your application. Create a user per app with access only to its own database.
  • No indexes on columns used in WHERE, JOIN and ORDER BY, so queries slow down as tables grow.
  • Confusing DATETIME and TIMESTAMP. TIMESTAMP converts to and from the connection's time zone; DATETIME stores exactly what you give it. Pick one deliberately and store times in UTC.
  • Old queries that break under ONLY_FULL_GROUP_BY, which modern MySQL enables by default. Every selected column must be grouped or aggregated.

Getting it online

On shared hosting, MySQL (or MariaDB) is already included - create a database and user in the control panel and manage it with phpMyAdmin. Our PHP + MySQL guide walks through it.

Off shared hosting, every major cloud offers managed MySQL (AWS RDS, Google Cloud SQL, Azure, DigitalOcean), with automated backups and updates.


← Back to Stack Picker All primers Compare databases