2015-02-06

Send to Kindle

Many of you have already heard about NoSQL databases and one of the the most used tool is Memcached, where you add a cache layer between the application and database. Since MySQL version 5.6, a new plugin is available to do the integration between MySQL and Memcached. On this article, we will learn how to install it on linux, and some basic configurations of it.

Pre-requirements:

Install libevent

Installation:

To install memcached support we will need to create a few tables responsible for MySQL and memcached integration. MySQL already includes the file which creates those tables (innodb_memcached_config.sql), you can find this file in a sub folder of your basedir. To discover where is your basedir, run the bellow command:

If you have installed MySQL via your distro repository, the path will be as follow:

In case you have used MySQL binaries, the path will be as follow:

Now we will run this .sql file. By default, the script creates a test table on test database, but on our tests we will use the memcached db:

Now let’s create our table to store memcached data:

Next step is to install memcached plugin on MySQL. To do it we will use INSTALL PLUGIN command:

To verify if the plugin was successful installed, we can run the bellow command:

Configuring and Using:

Now we will test memcached via some programming language, PHP in this case:

Now, let’s see what is stored on MySQL?

What happens if we change an entry manually on MySQL?

What about if we want to store the entries on a different MySQL table?

We just need to create a new table, add a new container and use the delimiter which is configured on config_options table from innodb_memcache database:

We have created a new table named dados2 and added a new container to refer to that table, which we named as bbb, now we just need to use that as prefix on memcached:

We also can map the table to store values into separate fields on the table.

Verify that on the config_options table we already have a separator configured:

This character we will use to store values into multiple columns. Let’s create a table and add it to a new container(we will specify the columns we want the values separated by comma ‘,’):

Now, lets create an array of products and add them to memcached:

Server/Service restart:

Let’s see what happens if we have to restart MySQL service(Same apply to server reboot)?

Will the data remain available on memcached after it?

That is it! Entries will remain available even after reboot’s/restart’s.

SELinux:

On environments where we have SELinux enabled, it can block memcached integration because MySQL is not allowed to listen on memcached port, where is a tip on how to allow it(I’m using CentOS as linux distro):

Search for entries containing mysqld and dinied keywords on /var/log/audit/audit.log , if you find any, type the bellow commands to create a new SELinux module to allow it:

Opcoes do memcached: In case you want to modify any memcached specific option, you can add the daemon_memcached_option to MySQL config file, for example, to change memcached port:

That is it, I hope you’ve learned how to install and configure MySQL and memcached plugin integration.

Send to Kindle

PlanetMySQL Voting: Vote UP / Vote DOWN

Show more