How to Import Data?

Memgraph comes with tools for importing data into the database. Currently, only import of CSV formatted is supported. We plan to support more formats in the future.

CSV Import Tool

CSV data should be in Neo4j CSV compatible format. Detailed format specification can be found here.

The import tool is run from the console, using the mg_import_csv command.

If you installed Memgraph using Docker, you will need to run the importer using the following command:

docker run -v mg_lib:/var/lib/memgraph -v mg_etc:/etc/memgraph -v mg_import:/import-data \
  --entrypoint=mg_import_csv memgraph

You can pass CSV files containing node data using the --nodes option. Multiple files can be specified by repeating the --nodes option. At least one node file should be specified. Similarly, graph edges (also known as relationships) are passed via the --relationships option. Multiple relationship files are imported by repeating the option. Unlike nodes, relationships are not required.

After reading the CSV files, the tool will by default search for the installed Memgraph configuration. If the configuration is found, the data will be written in the configured durability directory. If the configuration isn't found, you will need to use the --out option to specify the output file. You can use the same option to override the default behaviour.

Memgraph will recover the imported data on the next startup by looking in the durability directory.

For information on other options, run:

mg_import_csv --help

When using Docker, this translates to:

docker run --entrypoint=mg_import_csv memgraph --help


Let's import a simple dataset.

Store the following in comment_nodes.csv.

1,United Kingdom,Chrome,thanks,Message;Comment
3,France,Firefox,I see,Message;Comment
4,Italy,Internet Explorer,fine,Message;Comment

Now, let's add forum_nodes.csv.


And finally, set relationships between comments and forums in relationships.csv.


Now, you can import the dataset in Memgraph.

WARNING: Your existing recovery data will be considered obsolete, and Memgraph will load the new dataset.

Use the following command:

mg_import_csv --overwrite --nodes=comment_nodes.csv --nodes=forum_nodes.csv --relationships=relationships.csv

If using Docker, things are a bit more complicated. First you need to move the CSV files where the Docker image can see them:

mkdir -p /var/lib/docker/volumes/mg_import/_data
cp comment_nodes.csv forum_nodes.csv relationships.csv /var/lib/docker/volumes/mg_import/_data

Then, run the importer with the following:

docker run -v mg_lib:/var/lib/memgraph -v mg_etc:/etc/memgraph -v mg_import:/import-data \
  --entrypoint=mg_import_csv memgraph \
  --overwrite \
  --nodes=/import-data/comment_nodes.csv --nodes=/import-data/forum_nodes.csv \

Next time you run Memgraph, the dataset will be loaded.

Have a Question?

Reach out to us over Slack or email, we're always happy to help with code or other questions you might have.