Creating the Initial Database
Before we can do anything, we have to create an Mnesia database. You need to do this only once.
| $ erl |
| 1> mnesia:create_schema([node()]). |
| ok |
| 2> init:stop(). |
| ok |
| $ ls |
| Mnesia.nonode@nohost |
mnesia:create_schema(NodeList)
initiates a new Mnesia
database on all the nodes in NodeList
(which must be a
list of valid Erlang nodes). In our case, we gave the node list
as [node()]
, that is, the current node. Mnesia is
initialized and creates a directory structure called
Mnesia.nonode@nohost to store the
database. Then we exit from the Erlang shell and issue the
operating system’s ls command to
verify this.
If we repeat the exercise with a distributed node called
joe
, we get the following:
| $ erl -name joe ... |
Get Programming Erlang, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.