The not entirely right way to start mnesia is as an application.
application:start(mnesia).
before you start your application. It can be used when you are developing your system. For a real deployment, you want to generate a release
with a boot-script. A release is a self-contained Erlang system you can start up on a foreign machine. You will write your own application, write a my_application_name.app
file which contains a dependency on mnesia
. Then you want to generate a release, typically with reltool
and this release will then initialize by starting up mnesia before starting my_application_name
. At least this is the real way to do it.
The tool like rebar
can help you with maintaining your application and a reltool.config
file for building your release.
Note that Mnesia needs a schema before it can start. A common trick is to have your release contain a default empty database which gets installed such that mnesias dir
parameter points to it. Thus, if you start a newly generated system, it has a database to start from. And you can restart from scratch by re-installing the empty database. Check out FALLBACK.BUP
in mnesia for hints on how to do this.
As for your errors, you can't start your server twice. The first time around, it registers itself under the atom server
so a subsequent restart when it is already running will crash it. You can sometimes get a hint if you boot Erlang with the SASL application enabled. Either execute application:start(sasl)
or run erlang like so:
erl -boot start_sasl
which substitutes the normal boot script with a variant that also starts SASL.