Console Login

Stop Choking Your Database: A 2012 Guide to MySQL 5.5 Tuning on Linux

Stop Choking Your Database: A Survival Guide for MySQL 5.5

Let’s be honest: if you just ran yum install mysql-server on your CentOS 6 box and walked away, your database isn't running—it’s limping. I recently audited a high-traffic Magento store hosting local Norwegian fashion brands. They were pushing serious traffic during a flash sale, and the site fell over. Not because of PHP, and not because of Apache. It died because their database was trying to push 500 concurrent connections through a configuration designed for a 64MB RAM web server from 2005.

Disk I/O is the silent killer of web applications. In the virtualization world, this is compounded by "noisy neighbors"—other VPS instances on the same physical host stealing your Input/Output Operations Per Second (IOPS). If you are serious about performance in 2012, you need to understand the relationship between your my.cnf file, your file system, and the physical disk underneath.

The Hardware Reality: Spinning Rust vs. SSD

Before we touch a single config file, we need to talk about hardware. Most VPS providers in Europe are still running on SATA II spinning disks. For a file server, that’s fine. For a database doing random reads and writes? It’s a disaster.

Pro Tip: Check your disk latency. Run iostat -x 1. If your %util is hovering near 100% and your await time is over 10ms, your CPU is sitting idle waiting for the disk to spin. No amount of caching will fix a physical bottleneck.

This is why at CoolVDS, we have aggressively moved to Pure SSD (Solid State Drive) arrays for our high-performance tiers. The difference isn't just incremental; it’s exponential. We are seeing random write speeds jump from 150 IOPS on 15k SAS drives to over 5,000 IOPS on our SSD setups. If your current host is putting your database on shared spinning rust, you are fighting a losing battle.

The my.cnf Anatomy: Critical Flags for InnoDB

MySQL 5.5 has made InnoDB the default engine, which is great for data integrity (ACID compliance), but it needs RAM. Lots of it. The default configuration often sets the buffer pool to a pitiful 8MB.

Here is the baseline configuration I deploy for a 4GB RAM VPS dedicated to MySQL:

[mysqld]
# The most important setting. Set to 70-80% of TOTAL RAM if the server is dedicated to MySQL.
innodb_buffer_pool_size = 3G

# Avoid double buffering. Let InnoDB handle the disk, not the OS.
innodb_flush_method = O_DIRECT

# Stop using one giant file for all tables. This keeps your disk clean.
innodb_file_per_table = 1

# The log file size. Bigger means faster writes, but longer crash recovery.
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M

# If you don't need strict ACID compliance (e.g., losing 1 second of data is okay),
# change this from 1 to 2 for a massive speed boost.
innodb_flush_log_at_trx_commit = 2

The Query Cache Trap

There is a misconception that enabling the Query Cache is a magic "go fast" button. In high-concurrency environments, the Query Cache often becomes a bottleneck because of the global lock required to update it. Every time a table is written to, the cache for that table is invalidated.

If you have a write-heavy application, disable it:

query_cache_type = 0
query_cache_size = 0

File System Tuning: Ext4 vs. XFS

On CentOS 6, Ext4 is the default. It's robust, but for databases, I prefer XFS due to its superior handling of large files and parallel I/O. Regardless of the file system, you must mount your partitions with noatime. By default, Linux writes a timestamp every time a file is read. This effectively turns every database read into a write operation on the disk level.

Edit your /etc/fstab to look like this:

# <file system>       <mount point>   <type>  <options>       <dump>  <pass>
/dev/xvda1            /               ext4    defaults,noatime,barrier=0 1       1

Note: Setting barrier=0 can improve performance but risks data loss during a power outage. Since CoolVDS infrastructure is backed by redundant UPS and diesel generators in our Oslo and European datacenters, we can safely leverage this for extra speed.

The Norwegian Context: Latency and Law

Why does location matter? Light speed is finite. If your customers are in Oslo, Bergen, or Trondheim, hosting your database in a US datacenter introduces 100ms+ of latency per round trip. For a PHP application that makes 20 SQL queries to generate a page, that adds 2 full seconds of load time. That is an eternity in e-commerce.

Hosting locally isn't just about speed; it's about the Personopplysningsloven (Personal Data Act). While the EU Data Protection Directive provides a framework, the Norwegian Datatilsynet is rigorous. Keeping your customer data on servers physically located within the EEA (or specifically Norway) simplifies compliance significantly compared to navigating the complex Safe Harbor rules required for US hosting.

The Architecture of Stability

Tuning my.cnf is useless if the underlying virtualization technology is flawed. Many budget hosts use OpenVZ, which allows them to oversell RAM. When your neighbor consumes memory, the kernel invokes the OOM (Out of Memory) killer, and guess what process usually gets killed first? Your MySQL service.

This is why CoolVDS utilizes KVM (Kernel-based Virtual Machine) technology. KVM provides hardware virtualization with dedicated RAM allocation. When we assign 4GB to your instance, that physical RAM is locked to your kernel. No stealing, no surprises.

Final Verification

After applying these changes, restart MySQL and watch your logs:

service mysqld restart
tail -f /var/log/mysqld.log

Don't settle for default performance. Your database is the heart of your infrastructure. Give it the RAM, the SSD storage, and the KVM isolation it deserves.

Need a test environment? Deploy a CoolVDS SSD instance in our Oslo datacenter today. We guarantee the dedicated resources your database needs to breathe.