Home arrow MySQL arrow Page 3 - Take Some Load off MySQL with MemCached

Enter MemCached - MySQL

While the execution speed of your codebase can be a factor in the overall scalability of your application, more often than not, your database will become a bottleneck first. Modern web development environments can generally serve many page loads per second, and each of these pages will often make many requests to the database for fresh information. These pages may also be rendered by an easily expandable pool of web servers. While databases, including MySQL, are adequately designed to handle a significant number of queries, eventually, the load from all these requests can become too much to handle.

  1. Take Some Load off MySQL with MemCached
  2. A Solution - Caching
  3. Enter MemCached
  4. PHP MemCache PECL Extension
By: Chris Moyer
Rating: starstarstarstarstar / 6
July 29, 2008

print this article



MemCached is designed as a solution for low complexity caching. Data is stored as simple key-value pairs, with the two primary operations “get” and “set.” All data is stored in RAM allocated to the MemCache server. This allows for incredibly fast access times, generally beating those of a database handily.

Once you’ve installed MemCached on your system (from source, RPM, deb, or tarball), you’ll want to fire up an instance and allocate it some memory:

sudo /usr/bin/memcached -m 8 -p 11211 -u nobody -l

MemCached is now running, listening on port 11211 of your localhost ( interface, and using 8 Megabytes of memory. It’s running as user nobody to mitigate any security concerns. (At some point, you’ll want to add this command to your start-up scripts, ensuring that MemCached starts up with your server).

While you’ll generally access MemCached with a higher-level client API, you can get a feel for the system and the protocol used with a telnet client.

> telnet 11211

set mykey 0 0 13

Hello, World!


get mykey

VALUE mykey 0 13

Hello, World!



The lines beginning with “set” and “Hello, World!” after it are the basic set command. It tells MemCached to store some data for a given key:



KEYNAME can be any string up to 250 characters. FLAGS is used by client libraries to note any characteristic of the stored data. EXPIRES is 0 if the data should never expire, a number of seconds to retain the data, or a unix timestamp when the data should expire. BYTES is the size of the data to be stored and DATA is sent after a line break.

get [KEYNAME]\r\n

“get” is much simpler; it takes one parameter and returns the stored data.

>>> More MySQL Articles          >>> More By Chris Moyer

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Oracle Unveils MySQL 5.6
- MySQL Vulnerabilities Threaten Databases
- MySQL Cloud Options Expand with Google Cloud...
- MySQL 5.6 Prepped to Handle Demanding Web Use
- ScaleBase Service Virtualizes MySQL Databases
- Oracle Unveils MySQL Conversion Tools
- Akiban Opens Database Software for MySQL Use...
- Oracle Fixes MySQL Bug
- MySQL Databases Vulnerable to Password Hack
- MySQL: Overview of the ALTER TABLE Statement
- MySQL: How to Use the GRANT Statement
- MySQL: Creating, Listing, and Removing Datab...
- MySQL: Create, Show, and Describe Database T...
- MySQL Data and Table Types
- McAfee Releases Audit Plugin for MySQL Users

Developer Shed Affiliates


Dev Shed Tutorial Topics: