mark
mark

Reputation: 62866

Is it possible to instruct libmysqld (embedded MySql DB engine) to work with an in-memory database?

I have a zip archive with MySQL database files in it. I successfully read the database with libmysqld after I unzip the archive contents.

My question is this - does libmysqld understand the notion of an in-memory database? I could have extracted my zip archive into some memory structure and then had libmysqld work with it, instead of the files on disk. Is it possible?

Upvotes: 1

Views: 406

Answers (1)

Pete Wilson
Pete Wilson

Reputation: 8694

Yes, you can set up a table with storage engine = RAM. In fact, as I understand it, MySQL generally chooses RAM if it can: http://dev.mysql.com/doc/refman/5.1/en/memory-storage-engine.html . But, in my experience, you have to tell mySQL to copy a disk-resident table to a RAM table. That is, I've never been able to do what you might want: to bring the database into RAM from disk and then point MySQL at it and expect MySQL to understand it: for example, I don't believe that MySQL can grok an IDX file that used to be on disk and is now in RAM.

EDIT: You can create and copy the disk-resident table into the RAM table in one MySQL operation. The operation is:

CREATE TABLE Ramtable SELECT * FROM Disktable (Don't have to worry about capitalization: MySQL is case-agnostic wrt operations/requests.)

The description of the operation is here: http://www.plus2net.com/sql_tutorial/sql_copy_table.php .

I'm too lazy to edit my C-language code and post it, but it is super-simple. Just spend 15 or 20 mins reading the docs and you'll get it right away.

Upvotes: 1

Related Questions