Square CloudSquare Cloud

How much does it cost to host MySQL?

The cost of hosting MySQL comes from the instance's RAM and CPU, disk, backups and replicas. The Community server is free software (GPL), so you pay only for the infrastructure.

Updated 8 min read

Learning objectives

After reading this article you will be able to:

  • Understand what makes up the bill for a hosted MySQL database
  • Size RAM and disk with queries against your own database
  • Spot hidden costs such as the binary log, standby replicas and old versions
On this page

MySQL is free software: the Community server is released under the GPL and anyone can download it. What you pay for is the infrastructure around it: the machine that keeps it running, the disk that holds the data and logs, the backups and, if you want high availability, a second machine on standby. That is why the answer ranges from a web hosting plan that already bundles a database to an instance billed by the hour on a big cloud.

The general math for any database is in how much does a cloud database cost. This guide focuses on what is specific to MySQL: the InnoDB buffer pool, the binary log and the charges providers attach to them. Dollar figures are hypothetical, picked to keep the math simple; real prices are on the official pages listed in the sources.

What goes into the bill for a hosted MySQL database?#

  1. Compute (RAM and CPU): the biggest item. In MySQL, RAM goes mostly to the InnoDB buffer pool.
  2. Disk: data and indexes, plus the binary log, the redo logs and temporary tables.
  3. Backups: dumps or snapshots kept around, and retention beyond the included quota.
  4. High availability: a standby replica runs on a second machine, with its own disk.
  5. Traffic: queries from an application hosted on another network may pay for data transfer out.
  6. License: zero on Community. Oracle sells MySQL Enterprise Edition, with advanced features, tools and technical support, for those who need them.

If you are still picking an engine, what is MySQL and MariaDB vs MySQL help before you look at prices.

How do the common options bill?#

Option How it bills What to watch
Web hosting with MySQL included the database comes with the site's plan size and connection limits; remote access not always allowed
VPS fixed monthly price for the machine installation, updates, backups and TLS are on you
Amazon RDS for MySQL instance hours, provisioned storage, backups and data transfer Multi-AZ bills the standby instance; provisioned IOPS are billed even when unused
Azure Database for MySQL (Flexible Server) vCore-hours plus GB-months of storage high availability bills both the primary and the secondary
Fixed-plan platform monthly fee with RAM and resources included what the plan includes (backups, connections, traffic)

On Amazon RDS for MySQL, an instance is billed from launch until it is stopped or deleted, per second after a 10-minute minimum, and 1- or 3-year Reserved Instances don't cover storage or I/O. On Azure Database for MySQL, a stopped server pays no compute but keeps paying for storage, and backup storage has no extra charge up to 100% of provisioned storage.

The instance math works like PostgreSQL's: the hourly rate times about 730 hours a month, plus storage. The worked example is in how much does PostgreSQL hosting cost.

How much RAM does MySQL need?#

Almost all of MySQL's memory goes to the buffer pool, the area where InnoDB caches table data and indexes. A query that finds its pages in the buffer pool never touches the disk; when they don't fit, every read becomes I/O and the database slows down. The default innodb_buffer_pool_size is 128 MB, too small for production.

The manual offers a reference point in the innodb_dedicated_server option, which sizes the buffer pool on its own on a server dedicated to MySQL:

Server memory Buffer pool it sets
under 1 GB 128 MB (the default)
1 GB to 4 GB half the memory
over 4 GB 75% of the memory

The manual itself advises against that option when MySQL shares the machine with other applications. Beyond the buffer pool, each connection holds its own memory (the thread's stack and buffers), and sorts and scans allocate buffers per query. The default max_connections is 151, and several application instances with large pools hit that limit before RAM runs out. The guide on too many connections shows how to size the pool.

To check whether the buffer pool is the right size, run this on your current database:

sql
-- configured buffer pool size, in MB
SELECT @@innodb_buffer_pool_size / 1024 / 1024 AS buffer_pool_mb;

-- logical reads (read_requests) and reads that went to disk (reads)
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_read%';

-- peak connections since the server started, and the limit
SHOW GLOBAL STATUS LIKE 'Max_used_connections';
SHOW VARIABLES LIKE 'max_connections';

Divide Innodb_buffer_pool_reads by Innodb_buffer_pool_read_requests: the lower the ratio, the more reads come from memory. If it rises with traffic, your hot data no longer fits, and the fix is more RAM or better indexes, which cut what each query has to read.

How do you estimate disk, and what does the binary log hide?#

Start with the size of your tables and of the binary log:

sql
-- the 10 largest tables, data plus indexes, in MB
SELECT table_schema AS db, table_name AS tbl,
       ROUND((data_length + index_length) / 1024 / 1024, 1) AS mb
FROM information_schema.tables
WHERE table_schema NOT IN ('mysql', 'sys', 'information_schema', 'performance_schema')
ORDER BY data_length + index_length DESC
LIMIT 10;

-- binary log files and the size of each one, in bytes
SHOW BINARY LOGS;

-- how many days the binary log is kept
SELECT @@binlog_expire_logs_seconds / 86400 AS retention_days;

The information_schema sizes come from cached statistics, which by default can be up to 24 hours old; run ANALYZE TABLE on a table to refresh its numbers.

The binary log (binlog) records every change to the database and is used for replicas and for point-in-time recovery. In recent versions it is on by default, and each file only expires after 30 days. On a write-heavy database, that can take more disk than the data itself.

Hypothetical example: a 4 GB database that grows 300 MB a month and writes 200 MB of binlog a day. After 12 months, the data reaches 7.6 GB. With the default 30-day retention, the binlog holds 6 GB; with 7 days, 1.4 GB. With 30% headroom, the disk you need drops from about 18 GB to about 12 GB. At US$0.10 per GB-month (a hypothetical rate), the 6 GB difference costs US$0.60 a month. The real problem shows up on a fixed-size disk: when it fills, writes to the binary log wait for space (MySQL checks once a minute), and writes stall until you free some disk.

Lower the retention only if you don't rely on the binlog, because it is what lets you recover to a point between two backups. To delete old files, use PURGE BINARY LOGS, never rm, which leaves the binlog index out of date.

What hidden costs show up?#

  • Standby replica. On RDS, Multi-AZ keeps a standby instance in another Availability Zone, billed by the hour like the primary. On Azure, high availability bills compute and storage for both nodes.
  • Old versions. RDS charges RDS Extended Support, per vCPU-hour, when a MySQL major version keeps running past the end of standard support; the charges stop when you upgrade. Plan the move ahead, with dump and restore.
  • Provisioned IOPS. On RDS, you pay for the IOPS and storage you provision, not the ones you use.
  • Too many connections. Every new application instance opens its own pool, and the easy way out, a bigger database, is expensive. A smaller pool fixes it.
  • Unused indexes. Every index takes disk and buffer pool space. Drop the ones no query uses.
  • Traffic and exchange rates. An application and a database on different networks pay for data transfer, and dollar-priced services move with the exchange rate.

How do you cut the bill without risking your data?#

  1. Measure before buying RAM. If few reads go to disk, more memory changes nothing.
  2. Set binlog retention to what your backup strategy actually needs.
  3. Stop test environments where the provider allows it: a stopped server stops paying for compute.
  4. Keep the application and the database in the same datacenter: traffic and latency drop together.
  5. Keep off-machine backups with mysqldump --single-transaction, which exports a consistent state of InnoDB tables without blocking the application. The step by step is in how to back up your database.

How to do this on Square Cloud#

Square Cloud offers MySQL hosting from the Standard plan up, always on a recent version; Hobby doesn't include databases. You create the database in the dashboard (name, memory and engine) and it is ready in seconds, in the same datacenter as your applications, with about 1 ms of average latency and mandatory TLS. The dashboard gives you the full connection URL, shown once at creation, and the certificate to download; the connection is external, so you can also reach it from your machine and from CI.

The price is the plan's, in Brazilian reais, with no bandwidth or per-request charges (fair use policy): Standard costs R$44.99, R$64.99 or R$84.99 a month, with 4, 6 or 8 GB of RAM. That RAM is a pool shared by applications and databases, and each MySQL database uses at least 1024 MB of it: a 512 MB web API plus a 1024 MB MySQL database add up to 1.5 GB and fit on the 4 GB Standard, leaving 2.5 GB for other applications or databases. Each database is a fixed, single-node instance with up to 256 connections and no pooler in front, so size your application's pool.

Every plan with databases includes an automatic daily snapshot, kept for 7 days, with the most recent one kept for up to 30 days, and you can take manual snapshots, for example before a migration. A snapshot restores to the same database, to another MySQL database or to a new one, and also downloads as a .zip. Since there is no replica, keep a copy of your own outside the platform too if the data is critical. See the details on MySQL hosting.

Database hosting

MongoDB, PostgreSQL, MySQL and Redis next to your app

MySQL hosting

FAQs

Is MySQL free to use?

MySQL Community Edition is released under the GPL and is freely downloadable. Oracle sells MySQL Enterprise Edition, with advanced features, tools and technical support. When you host it, you pay for the machine, the disk and the services around it.

How much RAM does MySQL need?

Most of the memory goes to the InnoDB buffer pool, the cache for data and indexes, which defaults to 128 MB. On a dedicated server with 1 to 4 GB, the innodb_dedicated_server option gives it half the RAM. Measure the share of reads that hit disk to know whether memory is short.

Is shared web hosting with MySQL enough for a bot or an API?

Only if the plan allows remote database access, because a bot or API hosted elsewhere connects from outside. Also check the database size limit and the number of simultaneous connections before you sign up.

Why does MySQL's disk keep growing without new data?

A common culprit is the binary log, on by default in recent versions, which records every change and only expires after 30 days. Run SHOW BINARY LOGS to see its size and set binlog_expire_logs_seconds to what your backup strategy needs.

Next articleRedis: ECONNRESET, Socket closed unexpectedly and connection timeoutsRedis ECONNRESET, Socket closed unexpectedly and timeouts come from idle connections closed, the wrong TLS scheme or client limits. Fix them in Node.js and Python.

More in Databases

See all 32 articles