Getting Started with Readyset on MySQL!
4 min read
•
14 days ago
Optimizing MySQL and PostgreSQL performance is crucial for modern applications, especially those with read-heavy workloads. Readyset is a drop-in SQL caching engine that sits between your application and the database. It automatically caches query results to improve response times without requiring application changes.
In this post, we'll cover:
Installing Readyset on Ubuntu 24.04 using a .deb package
Configuring Readyset to connect to an upstream MySQL database
Running queries and caching results using MySQL's employee's sample database
Managing cached queries to optimize performance
Step 1: Prerequisites
Before installing Readyset, ensure you have a running MySQL or PostgreSQL database. Readyset requires access to the database to snapshot the schema and cache queries.
Key Recommendations
Readyset should be installed on a separate host from the database to avoid resource contention.
3The database server should allow Readyset to connect remotely.
For this tutorial, we assume:
- MySQL is running on 10.0.0.11:3306;
- Readyset is running on 10.0.0.12:3307;
- A database named employees is available;
- A MySQL user (`readyset`@`10.0.0.%`) with appropriate permissions exists:
If you haven't already set up the employees sample database, you can download it here and import it into MySQL.
Step 2: Installing Readyset on Ubuntu 24.04
2.1 Download the Readyset .deb Package
2.2 Install Readyset Using dpkg
After installation, you should see:
Step 3: Configuring Readyset
Before starting Readyset, you must configure its connection settings in /etc/readyset/readyset.conf.
3.1 Open the Configuration File
3.2 Set the Database Connection
Modify or add the following lines:
- UPSTREAM_DB_URL: Readyset needs this to connect to MySQL and snapshot the schema.
- LISTEN_ADDRESS: it defaults to 3307 for MySQL deployments and 5433 for PostgreSQL deployments, ensuring compatibility when running it on a separate host. You can bind it to a specific IP/DNS address or not.
3.3 Start the Readyset Service
To check if it's running:
Step 4: Connecting to Readyset
Once Readyset is running, connect using the MySQL client:
Since Readyset acts as a proxy, queries sent here will be cached automatically. For connecting to Readyset, I am assuming you have already created the below user on MySQL:
Step 5: Running Your First Cached Query
Run a real-world query using MySQL's employees database:
First Execution
Since this is the first run, Readyset still doesn't have a cache for this query, causing it to be proxied straightaway to MySQL. You can verify it using EXPLAIN LAST STATEMENT:
MySQL processes it as usual.
Step 6: Checking Proxied Queries
To check if Readyset intercepted the query:
Expected output:
Step 7: Creating a Cache for the Query
To explicitly cache this query:
I named the cache I created "my_query." If you don't give it a name, a string like "q_497640df754b2626" will be created automatically to identify your cache uniquely.
Expected output:
Step 8: Verifying the Cache
Check if the query is cached:
Expected output:
At this point, Readyset is caching this query!
Step 9: Running the Cached Query
Rerun the query, but now using Readyset:
Cached Execution
Query execution time dropped to 0.00 sec! 🚀
Readyset served the result from the cache, avoiding a full database query. We can validate it once again using the EXPLAIN LAST STATEMENT. Observe below where the query was executed:
Step 10: Removing a Cached Query
To remove the cache, run:
Verify that it's gone:
Expected output:
Conclusion
Using Readyset, you can significantly improve MySQL query performance with minimal effort.
With Readyset running on a separate host, you reduce database server overhead while ensuring cached queries execute efficiently.
Connect with US:
- Play with our Cloud Demo: https://readyset.cloud/
- Our Slack: https://readysetcommunity.slack.com/ssb/redirect
- Our Github: https://github.com/readysettech/readyset
Authors