Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 339 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I make a MySQL database run completely in memory?

#1
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.



Reply

#2
If your database is small enough (or if you add enough memory) your database will effectively run in memory since it your data will be cached after the first request.

Changing the database table definitions to use the memory engine is probably more complicated than you need.

If you have enough memory to load the tables into memory with the `MEMORY` engine, you have enough to tune the innodb settings to cache everything anyway.
Reply

#3
In place of the Memory storage engine, one can consider MySQL Cluster. It is said to give similar performance but to support disk-backed operation for durability. I've not tried it, but it looks promising (and been in development for a number of years).

[You can find the official MySQL Cluster documentation here.][1]


[1]:

[To see links please register here]

"MySQL Cluster CGE"
Reply

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

In direct response to this part of your question, you can issue an `ALTER TABLE tbl engine=InnoDB;` and it'll recreate the table in the proper engine.
Reply

#5
Assuming you understand the consequences of using the MEMORY engine as mentioned in comments, and [here][1], 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.


[1]:

[To see links please register here]

Reply

#6
Additional thoughts :

Ramdisk - setting the temp drive MySQL uses as a RAM disk, very easy to set up.

memcache - memcache server is easy to set up, use it to store the results of your queries for X amount of time.
Reply

#7
Memory Engine is not the solution you're looking for. You lose everything that you went to a database for in the first place (i.e. ACID).

Here are some better alternatives:

1. <del>Don't use joins - very few large apps do this (i.e Google, Flickr, NetFlix), because it sucks for large sets of joins. </del>

> A LEFT [OUTER] JOIN can be faster than an equivalent subquery because
> the server might be able to optimize it better—a fact that is not
> specific to MySQL Server alone.
>
> -[The MySQL Manual][1]

2. Make sure the columns you're querying against have indexes. Use EXPLAIN to confirm they are being used.
3. Use and increase your Query_Cache and memory space for your indexes to get them in memory and store frequent lookups.
4. Denormalize your schema, especially for simple joins (i.e. get fooId from barMap).

The last point is key. I used to love joins, but then had to run joins on a few tables with 100M+ rows. No good. Better off insert the data you're joining against into that target table (if it's not too much) and query against indexed columns and you'll get your query in a few ms.

I hope those help.


[1]:

[To see links please register here]

Reply

#8
It is also possible to place the MySQL data directory in a *tmpfs* in thus speeding up the database write and read calls. It might not be the most efficient way to do this but sometimes you can't just change the storage engine.

Here is my fstab entry for my MySQL data directory

none /opt/mysql/server-5.6/data tmpfs defaults,size=1000M,uid=999,gid=1000,mode=0700 0 0

You may also want to take a look at the *innodb_flush_log_at_trx_commit=2* setting. Maybe this will speedup your MySQL sufficently.

innodb_flush_log_at_trx_commit changes the mysql disk flush behaviour. When set to 2 it will only flush the buffer every second. By default each insert will cause a flush and thus cause more IO load.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through