Skip to main content
Version: 2.10.1

Migrate MySQL database to Memgraph

Related - Tutorial

Prerequisites

  • A running MySQL instance with the database you wish to migrate.
  • A running Memgraph instance where you want to migrate the data.
  • The mgmigrate tool installed. Installation instructions can be found here.

How to migrate data from MySQL to Memgraph?

Dataset

To show you how to migrate data from MySQL to Memgraph we will be working with a MySQL database named users_db that contains two tables, users and user_relationships:

The users table contains four users with their ids and names:

mysql> SELECT * FROM users;
+----+------+
| id | name |
+----+------+
| 0 | Anna |
| 1 | Josh |
| 2 | Lisa |
| 3 | Troy |
+----+------+

Migrating

1. You can migrate this database into Memgraph by running:

build/src/mgmigrate --source-kind=mysql /
--source-host 127.0.0.1 /
--source-port 33060 /
--source-username root /
--source-password mysql /
--source-database=users_db /
--destination-host 127.0.0.1 /
--destination-port 7687 /
--destination-use-ssl=false

2. Run the following query in Memgraph Lab or mgconsole to see the results:

MATCH (n)-[r]-(m) RETURN n,r,m;

The query results should be:

memgraph> MATCH (n)-[r]-(m) RETURN n,r,m;
+--------------------------------+--------------------------------+--------------------------------+
| n | r | m |
+--------------------------------+--------------------------------+--------------------------------+
| (:users {id: 1, name: "Josh"}) | [:user_relationships] | (:users {id: 0, name: "Anna"}) |
| (:users {id: 0, name: "Anna"}) | [:user_relationships] | (:users {id: 1, name: "Josh"}) |
| (:users {id: 3, name: "Troy"}) | [:user_relationships] | (:users {id: 2, name: "Lisa"}) |
| (:users {id: 2, name: "Lisa"}) | [:user_relationships] | (:users {id: 3, name: "Troy"}) |
+--------------------------------+--------------------------------+--------------------------------+