问题
It seems like that we can launch Mnesia only by typing iex --erl "--mnesia dir '~/doc/'" --name mynode
.
Can we just launch it without passing arguments to erl?
回答1:
You can set it up dynamically in your code. All the --erl
instruction above does is to configure the mnesia application before it is started. You could achieve this by:
# First load mnesia
iex(1)> :application.load(:mnesia)
:ok
# Now configure the desired directory
iex(2)> :application.set_env(:mnesia, :dir, 'sample')
:ok
# Start mnesia as usual
iex(3)> :mnesia.start
:ok
# See if the desired info is correct
iex(4)> :mnesia.info
:ok
Notice it only works if you start the application manually. If you are starting it automatically and want to configure through the command line, your current snippet is the best option (or using ELIXIR_ERL_OPTS
).
来源:https://stackoverflow.com/questions/21150613/is-there-a-built-in-mechanism-for-us-to-launch-mnesia-in-elixir