Loading Data •User-created  MEMORY  tables are never converted to disk tables. Loading Data MEMORY Tables and Replication Managing Memory Use 3414 mysql>  SET max_heap_table_size = 1024*1024; Query OK, 0 rows affected (0.00 sec) mysql>  CREATE TABLE t1 (id INT, UNIQUE(id)) ENGINE = MEMORY; Query OK, 0 rows affected (0.01 sec) mysql>  SET max_heap_table_size = 1024*1024*2; Query OK, 0 rows affected (0.00 sec) mysql>  CREATE TABLE t2 (id INT, UNIQUE(id)) ENGINE = MEMORY; SUM_OVER_ALL_BTREE_KEYS( max_length_of_key  + sizeof(char*) * 4) + SUM_OVER_ALL_HASH_KEYS(sizeof(char*) * 2) + ALIGN( length_of_row +1, sizeof(char*)) To populate a  MEMORY  table when the MySQL server starts, you can use the  init_file  system variable. For example, you can put statements such as  INSERT INTO ... SELECT  or  LOAD DATA  into a file to load the table from a persistent data source, and use  init_file  to name the file. See Section 5.1.8, “Server System Variables” , and Section 13.2.7, “LOAD DATA Statement” . When a replication source server shuts down and restarts, its  MEMORY  tables become empty. To replicate this effect to replicas, the first time that the source uses a given  MEMORY  table after startup, it logs an event that notifies replicas that the table must be emptied by writing a  DELETE  or (from MySQL 8.0.22) TRUNCATE TABLE  statement for that table to the binary log. When a replica server shuts down and restarts, its  MEMORY  tables also become empty, and it writes a  DELETE  or (from MySQL 8.0.22)  TRUNCATE TABLE  statement to its own binary log, which is passed on to any downstream replicas. When you use  MEMORY  tables in a replication topology, in some situations, the table on the source and the table on the replica can differ. For information on handling each of these situations to prevent stale reads or errors, see Section 17.5.1.21, “Replication and MEMORY Tables” . The server needs sufficient memory to maintain all  MEMORY  tables that are in use at the same time. Memory is not reclaimed if you delete individual rows from a  MEMORY  table. Memory is reclaimed only when the entire table is deleted. Memory that was previously used for deleted rows is re-used for new rows within the same table. To free all the memory used by a  MEMORY  table when you no longer require its contents, execute  DELETE  or  TRUNCATE TABLE  to remove all rows, or remove the table altogether using  DROP TABLE . To free up the memory used by deleted rows, use  ALTER TABLE ENGINE=MEMORY to force a table rebuild. The memory needed for one row in a  MEMORY  table is calculated using the following expression: ALIGN()  represents a round-up factor to cause the row length to be an exact multiple of the  char  pointer size.  sizeof(char*)  is 4 on 32-bit machines and 8 on 64-bit machines. As mentioned earlier, the  max_heap_table_size  system variable sets the limit on the maximum size of  MEMORY  tables. To control the maximum size for individual tables, set the session value of this variable before creating each table. (Do not change the global  max_heap_table_size  value unless you intend the value to be used for  MEMORY  tables created by all clients.) The following example creates two  MEMORY tables, with a maximum size of 1MB and 2MB, respectively: