Automatically Loading MySQL Memory Tables on MySQL Startup or Reboot
Published October 28th, 2008Problem Statement:
If you use MySQL memory tables a lot to speed up frequently used but rarely changed data, you are faced with a problem of loading the memory tables manually whenever you start or reboot your MySQL server. You need an automated of loading the memory tables; here we will show you how.
Solution
To load MySQL memory tables with data from existing physical tables, you can do the following:
- Edit your /etc/my.cnf file and add the following line under the [mysqld] section:
- Now create a text file called /etc/my.memory.tables.init.sql file to to have a statement such as the following for each memory table to load from a physical table:
- Restart your MySQL server
- You should check of your memory tables and notice that they have data from physical tables
init_file=/etc/my.memory.tables.init.sql
INSERT into db_name.memory_table SELECT * FROM db_name.physical_table;
Make sure your SQL statements are prefixed with database name as we show in the above-mentioned sample query; this will make sure the statements load data from the correct database.
liz on November 30, 2008
Hello Kabir,
I have gone through this and found the following lines to be confusing. Please revise.
“You need an automated of loading the memory tables;”
“Now create a text file called /etc/my.memory.tables.init.sql file to to have a statement”
“this will make sure the statements load data from the correct database.”
Thanks.