You get a bonus - 1 coin for daily activity. Now you have 1 coin

MySQL MEMORY vs Redis and NoSQL: Performance and Storage Comparison

Lecture



MySQL and Redis are often compared to each other, since both systems are capable of storing data in RAM and providing very high access speeds. However, their purpose and operating principles differ substantially. MySQL with the MEMORY engine is a relational database in which tables are temporarily placed in RAM and accessed through the familiar SQL language. Redis, in contrast, is a specialized NoSQL in-memory database optimized for the fastest possible key-based access and for working with various data structures.

In this article we will examine the key differences between MySQL MEMORY and Redis, compare their performance, data storage methods, behavior when RAM fills up, and scaling capabilities, and also explore in which scenarios each technology is the most suitable choice.

MySQL requires a defined and structured schema.

NoSQL allows you to store any data in a «document».

MySQL is backed by a huge community.

NoSQL has a small but rapidly growing community.

NoSQL is distinguished by ease of scaling.

MySQL requires more management.

MySQL uses SQL, which is applied across many types of
databases. NoSQL is a database
based on a design with popular implementations

MySQL uses a standard query language (SQL).

NoSQL does not use a standard query language.

MySQL has many excellent reporting tools.
NoSQL offers a few reporting tools that are difficult to standardize.

MySQL may run into performance issues with big data.

NoSQL delivers excellent performance on big data.

When comparing MySQL with the MEMORY engine (formerly HEAP) and Redis, it is important to understand that these are solutions for different tasks. Even though both use RAM, their architectures differ greatly.

Criterion MySQL MEMORY Redis
Data model

Relational tables, however it is possible to store a key and field in JSON,

which is equivalent to Redis

NoSQL (key → value and complex data structures)
Query language Full SQL Redis commands (GET, SET, HSET, ZADD, etc.)
Relations (JOIN) Yes No
Indexes B-tree and Hash Not needed — O(1) key-based access
Speed Very high Usually higher than MySQL MEMORY
Transactions SQL transactions (with MEMORY engine limitations) MULTI/EXEC, Lua scripts
Data types Table Strings, lists, sets, hashes, sorted sets, streams, and more
Persistent storage No (data is lost on restart) Optionally available (RDB, AOF)
Replication Through MySQL Built-in
Clustering Through MySQL Cluster and others Built-in Redis Cluster
Situation MySQL MEMORY Redis
RAM runs out New records are not inserted, the query returns an error Behavior depends on the maxmemory setting
Already existing data Remains accessible May be deleted automatically or the write will be rejected
Server operation MySQL keeps running Redis keeps running, but acts according to the memory policy

MySQL MEMORY

ENGINE=MEMORY tables use RAM to store rows.

If there is no memory left:

  • INSERT and UPDATE may fail with an error.
  • Already existing data continues to be readable.
  • The table does not "evict" old records automatically.
  • After restarting MySQL, all data from MEMORY tables disappears.

Example error:

ERROR 1114 (HY000): The table 'cache' is full

Moreover, the cause may lie not only in a lack of physical memory, but also in reaching the max_heap_table_size or tmp_table_size limits.

Redis

Redis also stores data in RAM, but has more flexible memory management.

If memory is full and the maxmemory parameter is set, various scenarios are possible:

  1. noeviction (the default in many configurations)
    • new writes are rejected;
    • reading continues to work.
  2. allkeys-lru
    • keys that have not been used for a long time are deleted automatically;
    • new data is written.
  3. volatile-lru
    • only keys with a TTL are deleted.
  4. allkeys-lfu
    • rarely used keys are deleted.
  5. volatile-ttl
    • keys whose time to live is about to expire are deleted first.

Therefore Redis can work as a true cache, freeing up memory on its own.

What happens when physical RAM is completely full?

If all of the computer's RAM is occupied:

  • the operating system may start actively using the swap file, which will sharply reduce performance;
  • if swap runs out, Linux may launch the OOM Killer (Out of Memory Killer), which will terminate one or more processes to free up memory. This could be either mysqld or redis-server, if they are the ones consuming the most memory.

The main difference

MySQL MEMORY

  • This is a regular MySQL table stored in RAM.
  • The familiar SQL is used.
  • Suitable if MySQL is already in use and you need to speed up temporary tables.
  • After a server restart, the data disappears.

Example:

CREATE TABLE cache (
    id INT PRIMARY KEY,
    value VARCHAR(255)
) ENGINE=MEMORY;

Redis

  • This is a standalone NoSQL DBMS.
  • All operations are oriented toward working with keys.
  • Optimized for millions of operations per second.
  • Can save data to disk and restore it after a restart.

Example:

SET user:1 "Alex"
GET user:1

or

HSET user:1 name Alex age 25

Performance

For a simple key-based read:

  • Redis — roughly 500 thousand to several million operations/s on a modern server.
  • MySQL MEMORY — usually tens or hundreds of thousands of queries/s, since it goes through the SQL parser, query optimizer, and table engine.

In other words, Redis is almost always faster for operations of the «get value by key» kind.

When to use MySQL MEMORY

  • Temporary tables.
  • Intermediate computation results.
  • When you need SQL queries, JOIN, GROUP BY.
  • When the application is already fully built around MySQL.

When to use Redis

  • Caching.
  • Storing user sessions.
  • Counters, rankings, message queues.
  • Pub/Sub.
  • Rate Limiting.
  • Fast data structures (sets, queues, sorted sets).

Conclusion

  • MySQL MEMORY — this is an in-memory relational database that retains all the advantages of SQL, but is not designed for extremely fast key-based operations.
  • Redis — this is a specialized in-memory NoSQL DBMS, which almost always wins in speed and scalability when the task comes down to fast key-based access and working with data structures.
  • MySQL MEMORY: memory runs out → the table becomes "full", new records are impossible until memory is freed or limits are increased.
  • Redis: memory runs out → either writes are rejected, or old keys are deleted automatically (if an eviction policy is configured).
  • If the system runs out of all RAM, the consequences are determined by the operating system, not by the DBMSs themselves. Redis is better suited to the role of a cache thanks to its built-in memory management mechanisms.

Therefore they are not so much competitors as complements to each other: in real-world systems MySQL is often used as the primary data store, while Redis — as a high-performance cache or a database for temporary data.

created: 2026-07-12
updated: 2026-07-12
1



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Databases - Redis DB Nosql"

Terms: Databases - Redis DB Nosql