I am writing data to Mnesia from one erlang VM, now I started another erlang VM on same machine, can second VM read the data written to mnesia by first VM.
Asked
Active
Viewed 153 times
1
-
Possible duplicate of [How to add a node to an mnesia cluster?](https://stackoverflow.com/questions/787755/how-to-add-a-node-to-an-mnesia-cluster) – Dániel Szoboszlay Jan 17 '19 at 23:06
2 Answers
1
To share Mnesia tables the nodes must be part of the same distributed Erlang system.
The schema defines which nodes contain the data base, cf. http://erlang.org/doc/apps/mnesia/Mnesia_chap3.html#define-a-schema
Mnesia database replication is described here: http://erlang.org/doc/apps/mnesia/Mnesia_chap5.html#distribution-and-fault-tolerance.
You can use mnesia:set_master_nodes() to define where to find a table.

Xypron
- 2,215
- 1
- 12
- 24
1
Ofcourse you can, here is some basic way to do it:
- Start the two nodes -
iex --name nodeA@127.0.0.1
andiex --name nodeB@127.0.0.1
- From the terminal of node A -
Node.connect :"nodeB@127.0.0.1"
- From the terminal of node A -
:mnesia.create_schema [node(), :"nodeB@127.0.0.1"]
- For node A and node B -
:mnesia.start
- From the terminal of node A -
create_table(Person, [attributes: [:id, :name]])
- From the terminal of node B -
:mnesia.dirty_write({Person, 1, "John"})
- Now you can get the information that node B has written from node A through doing basic selection -
:mnesia.dirty_read({Person, 1})
References: https://elixirschool.com/en/lessons/specifics/mnesia/# http://erlang.org/doc/apps/mnesia/

Tano
- 1,285
- 1
- 18
- 38