Database is a word that shows up in the description of almost any hosting plan, but it is not always clear what stands behind it and how a database differs from an ordinary text file. Here is a plain explanation of how a database is built, what SQL has to do with it, and when a site actually needs a dedicated DBMS.
What a database is in plain words
A database is an organized set of data stored so that it can be quickly found, changed, and linked to other data. Unlike a text file, where finding the right line turns into reading the whole content sequentially, a database stores records in tables with a strict structure and uses indexes for instant access.
For a site, the database usually stores whatever changes: article text, the list of products, user accounts, comments. The site's own code — PHP, templates, images — lives separately in the file system, while the database is responsible for the variable part of the content.
Types of databases
Web projects most often rely on a few kinds of DBMS, each suited to a different sort of task.
- Relational databases — data is stored in linked tables with a strict schema, examples are MySQL and MariaDB.
- Document databases — data is stored as flexible JSON-like documents without a rigid schema, an example is MongoDB.
- Key-value stores — the simplest model of storing key-value pairs, used mostly for caching.
- Embedded databases — work without a separate server, keep everything in one file, an example is SQLite.
Comparing a database and a plain file
The difference becomes especially clear once there is a lot of data and even more concurrent requests.
| Criterion | Text file | Database |
|---|---|---|
| Finding a record | sequential read of the whole file | index, instant access |
| Concurrent access | risk of corruption on parallel writes | transactions and locks managed by the DBMS |
| Links between data | must be maintained manually | foreign keys and relations between tables |
| Complex queries | require writing a separate script | one SQL query with conditions and sorting |
How SQL works in plain words
SQL (Structured Query Language) is the language an application uses to talk to a relational database: asking for records, changing them, or removing them. The syntax reads almost like an ordinary English sentence, which is what makes SQL convenient for describing queries.
-- Get all users from Kyiv
SELECT name, email FROM users WHERE city = 'Kyiv';
-- Update an order's status
UPDATE orders SET status = 'paid' WHERE id = 42;
The first query selects rows by a condition, the second changes an already existing record. The DBMS itself keeps track of executing such queries, and a developer does not need to manually search for a line in a file and rewrite the whole thing.
What to do when a site needs a database
- Identify the type of data: if strict relations and reporting are needed, a relational DBMS such as MariaDB usually fits.
- Create the database and a separate user with rights only to it, instead of using a shared administrative account for the site.
- Set up regular backups of the database separately from the backups of the site's files.
- Check the access rights of the specific database user so the application cannot perform operations it does not need.
- Watch the database size grow and move it to a more powerful plan in time if performance starts falling short.
A detailed guide to setting up a specific DBMS is in the article about setting up MariaDB on a VDS, and access rights for applications are covered in the article about MySQL user privileges. If the database is already running and needs to move to another server, the article about migrating a database is useful.
Frequently asked questions
What is the difference between a database and a database server?
A database is the data itself and its structure, while a database server (DBMS) is the program that manages that data: accepting requests, executing them, and returning the result. A single DBMS server can run several separate databases at once.
Does a simple brochure site need a database?
For a static site without feedback forms and without an admin panel, a database is usually not required — plain files are enough. But even a simple CMS for editing text through a browser most often stores content in a database.
What is a SQL database and how does it work in practice?
The term "SQL database" usually means a relational database managed through the SQL language: the application sends a text query, the DBMS parses it, finds the needed rows in the tables, and returns the result to the client. This cycle repeats on every request to the site.