Migrate MySQL database to Memgraph
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​
For this tutorial, we will be working with a MySQL database named users_db
that contains two tables, users
and user_relationships
:
- Table 'users'
- Table '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 |
+----+------+
The user_relationships
table contains the relationships between users:
mysql> SELECT * FROM user_relationships;
+----------+----------+
| user_one | user_two |
+----------+----------+
| 0 | 1 |
| 2 | 3 |
+----------+----------+
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:
- mgconsole
- Memgraph Lab
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"}) |
+--------------------------------+--------------------------------+--------------------------------+