MySQL

The pick when you're on shared hosting - it's already installed and waiting.

MySQL is one of the most widely deployed databases in the world, and on shared hosting it's usually the only one on offer. That's not a compromise: it's a mature, fast relational database, and the SQL you learn on it carries over almost entirely to PostgreSQL and others.


Who gets this pick

MySQL is the database result whenever you're on shared hosting and your data isn't real-time. Shared hosts include MySQL (or its compatible fork, MariaDB) with one-click setup and phpMyAdmin, while PostgreSQL and MongoDB are rarely available - so hosting decides it before scale or data shape are considered.


Why MySQL fits

You can create a database, a user and your first table in the control panel in a few minutes, without installing or configuring anything. phpMyAdmin gives you a visual view of your tables and a box to run SQL, which is a genuinely good way to learn. And PHP's PDO extension talks to it out of the box.

Many hosts actually run MariaDB, which began as a fork of MySQL. For everything a beginner does, the two are interchangeable - same SQL, same tools, same PHP code.


A first schema: a tiny blog

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  email VARCHAR(255) NOT NULL UNIQUE,
  password_hash VARCHAR(255) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE posts (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT NOT NULL,
  title VARCHAR(200) NOT NULL,
  body TEXT NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (user_id) REFERENCES users(id)
);

Create both tables in phpMyAdmin's SQL tab, insert a few rows by hand, then practise the queries a blog needs: the latest ten posts, all posts by one user, and posts joined with their author's email. When those feel natural, add a comments table and write the join yourself.

For a complete working example with PHP, follow the PHP + MySQL guestbook guide.


Setup details that matter later

  • Use utf8mb4 for the database and connection character set. MySQL's older utf8 can't store emoji and some other characters.
  • Use InnoDB tables (the default today). They support transactions and foreign keys.
  • Create a dedicated user per application with access only to its own database.
  • Add indexes to columns you filter or join on often - posts.user_id in the example above already gets one from its foreign key.

Backups

Most shared hosts take backups, but check how often and how long they're kept. Before any big change, export your database yourself from phpMyAdmin (or with mysqldump if you have SSH access) and keep a copy off the server.


Mistakes to avoid

  • Building SQL by gluing strings together with user input. Use prepared statements - always.
  • Storing lists in a single column, like tags = "php,mysql,web". That's a separate table waiting to happen.
  • Plain-text or MD5 passwords. Store the output of PHP's password_hash() in a VARCHAR(255).
  • No foreign keys, leaving orphaned rows when parents are deleted.
  • Never testing a restore. A backup you've never restored is a hope, not a backup.

If you leave shared hosting

Moving to a VPS or a platform service opens up PostgreSQL, which Stack Picker recommends for most projects off shared hosting. Your SQL knowledge transfers almost entirely - see MySQL vs PostgreSQL for the differences you'll notice.


Take the quiz All picks