Table of Contents

Choose a different version or distribution

Introduction

Before discussing how to install Memgraph on Ubuntu 20.04, let's take a moment to understand what Memgraph is.

Memgraph is an in-memory graph database designed for real-time data use-cases. It offers full ACID-compliant transactions and strong consistency, utilizing the RAFT algorithm for replication.

In this tutorial, you will install Memgraph on Ubuntu 20.04. Additionally, we will address some frequently asked questions about Memgraph.

Install Docker

1) To get started, install the Docker engine. The Memgraph Docker image is built on Docker Version 1.12 or higher, so it's compatible with all newer versions.

2) Once you have installed Docker, use the following command to pull the Memgraph Docker image:

docker pull memgraph/memgraph-platform

3) Use the following command to start Memgraph:

docker run -it -p 7687:7687 -p 7444:7444 -p 3000:3000 memgraph/memgraph-platform

If successful, you will see the following output:

Output 

Memgraph Lab is running at localhost:3000

mgconsole 1.3
Connected to 'memgraph://127.0.0.1:7687'
Type :help for shell usage
Quit the shell by typing Ctrl-D(eof) or :quit
memgraph> |

You can now submit queries on Memgraph.

Configuration

The configuration for Memgraph can be found in Docker's named volume mg_etc. On Linux systems, it is located at /var/lib/docker/volumes/mg_etc/_data/memgraph.conf.

Named Volumes

In case named volumes are reused between different Memgraph versions, Docker will overwrite the folder within the container with existing data from the host machine. This could lead to incompatibility issues, resulting in certain features not working properly or Memgraph not working at all. To avoid this, use different named volumes for different Memgraph versions. To remove the existing volume from the host, use the following command:

docker volume rm <volume_name>

Note for OS X/macOS users

If you encounter minor issues after installing Docker, this could be because the Memgraph Docker container is running on a custom IP address instead of localhost.

Determine the ID of the Memgraph container.

Issue the command docker ps to get an output similar to this:

CONTAINER ID        IMAGE               COMMAND                  CREATED        ...
8554329gf60a        memgraph            "/usr/lib/memgraph/m…"   2 seconds ago  ...

The container ID of the Memgraph image should be kept in mind, in this case it is 8554329gf60a

Now, use the container ID to retrieve an IP of the container.

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 9397623cd87e

Revealing the IP address is necessary when connecting to Memgraph with the mg_client via Docker. Instead of using HOST, use the IP address.

Querying

Memgraph, developed by Neo4j, supports the openCypher query language. It was designed specifically for interacting with graph databases.

To execute openCypher queries on Memgraph, use the command-line tool, mgconsole, which is installed with Memgraph itself.

If you have installed Memgraph using Docker, run the following command, replacing HOST with a valid IP address:

docker run -it --entrypoint=mgconsole memgraph --host HOST

Connect to a running Memgraph instance using the following command:

mgconsole

Instead, you can also run the container with following command to get memgraph prompt:

docker run -it -p 7687:7687 -p 7444:7444 -p 3000:3000 memgraph/memgraph-platform

Once it has started, a command prompt similar to the following will appear:

mgconsole 1.3
Connected to 'memgraph://127.0.0.1:7687'
Type :help for shell usage
Quit the shell by typing Ctrl-D(eof) or :quit
memgraph> |

You can now execute openCypher queries on Memgraph. Ensure each query ends with a semicolon ;. For example:

CREATE (u:User {name: "PWSUSER"})-[:Likes]->(m:Software {name: "Memgraph"});

Two nodes will be created in the database: one labeled User with the name VegaUser, and the other labeled Software with the name Memgraph. Additionally, a relationship will be created: VegaUser likes Memgraph.

Execute the query below to find created nodes and relationships.

MATCH (u:User)-[r]->(x) RETURN u, r, x;

Stopping Memgraph

If the Memgraph configuration is modified, it must be restarted. To do so, if you installed Memgraph using Docker, press Ctrl-C to stop it.

Alternatively, you can shut down the Memgraph server using the following command:

systemctl stop memgraph

Telemetry

Telemeter is an automated process for collecting data remotely. Memgraph leverages telemetry to optimize its product, gathering data about the machines running the database (e.g. CPU, memory, OS, and kernel info) as well as data about the database's runtime (CPU usage, memory usage, number of vertices and edges).

You can disable Memgraph's telemetry features by either altering the line in /etc/memgraph/memgraph.conf or by including --telemetry-enabled=false as a command-line argument when running the executable. To disable, set --telemetry-enabled=false instead of --telemetry-enabled=true.

FAQ's to Install Memgraph on Ubuntu 20.04

Does Memgraph lose all data upon system failure or restart due to its in-memory nature?

No. Memgraph primarily stores data in RAM, but it also continuously backs up data to disk with transaction logs and periodic snapshots. This ensures that, upon restart, Memgraph can recover its state to what it was before shutting down.

Does Memgraph have an API?

Yes. Memgraph has an API for both Java and Python, which allows for a range of operations, such as creating nodes and edges, running queries, and more.

Does Memgraph support multi-threading?

Yes. Memgraph utilizes a multithreaded architecture, which enables it to achieve better performance than single-threaded architectures. This allows for parallel execution of queries and better utilization of server resources.

Conclusion

We hope this detailed tutorial helped you understand how to install, configure, and modify Memgraph. To learn more about Memgraph installation, check out the official Memgraph Installation Documentation.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.