Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a MySQL database run completely in memory?

Tags:

database

mysql

I noticed that my database server supports the Memory database engine. I want to make a database I have already made running InnoDB run completely in memory for performance.

How do I do that? I explored PHPMyAdmin, and I can't find a "change engine" functionality.

like image 318
John Hoffman Avatar asked May 21 '12 20:05

John Hoffman


People also ask

Does MySQL run in-memory?

MySQL allocates buffers and caches to improve performance of database operations. The default configuration is designed to permit a MySQL server to start on a virtual machine that has approximately 512MB of RAM.

Is MySQL in-memory or on disk?

MySQL offeringsIn all engines, actions are performed in RAM. The Engines differ significantly in how good they are at making sure the data "persists" on disk. ENGINE=MEMORY -- This is not persistent; the data is found only in RAM.

How do I create an in-memory database?

Use create inmemory database to create an in-memory database, using model or another user database as its template. You can also create temporary databases as in-memory databases that reside entirely in in-memory storage. However, you cannot specify a template database for an in-memory temporary database.


1 Answers

Assuming you understand the consequences of using the MEMORY engine as mentioned in comments, and here, as well as some others you'll find by searching about (no transaction safety, locking issues, etc) - you can proceed as follows:

MEMORY tables are stored differently than InnoDB, so you'll need to use an export/import strategy. First dump each table separately to a file using SELECT * FROM tablename INTO OUTFILE 'table_filename'. Create the MEMORY database and recreate the tables you'll be using with this syntax: CREATE TABLE tablename (...) ENGINE = MEMORY;. You can then import your data using LOAD DATA INFILE 'table_filename' INTO TABLE tablename for each table.

like image 195
PinnyM Avatar answered Sep 22 '22 05:09

PinnyM