This is the command-line tool you use to retrieve and map the metadata from your relational database and drive the export from the relational and import into Neo4j database.
With the graphical user interface you can preview the resulting graph data model and eventually adapt it by changing labels, property names, relationship-types and property types.
It supports all relational databases with a JDBC driver, like MySQL, PostgreSQL, Oracle and Microsoft SQL.
You can get the latest version of the import tool from GitHub.
Once downloaded and uncompressed the operating system specific zip
/ tar.gz
, you also need download the proper JDBC Driver and add it to the lib
folder.
You can follow the proper link in the below table in order to download the proper driver jar
Vendor | JDBC Driver URL |
---|---|
http://www.oracle.com/technetwork/database/features/jdbc/default-2280470.html |
|
https://www.microsoft.com/en-us/download/details.aspx?id=55539 |
Note
|
For very large databases make sure to have enough disk-space for the CSV export and the Neo4j datastore and enough RAM and CPUs to finish the import quickly. |
There are two ways for write Etl parameters: 1) write parameters in command line: $NEO4J_HOME/bin/neo4j-etl export|generate-metadata-mapping --rdbms:url jdbc:oracle:thin:@localhost:49161:XE --rdbms:user northwind --rdbms :password northwind --rdbms:schema northwind --using bulk:neo4j-import --import-tool $NEO4J_HOME/bin --csv-directory /tmp/northwind --options-file /tmp/northwind/options.json --quote '"' --force ... 2) use a config file: $NEO4J_HOME/bin/neo4j-etl export|generate-metadata-mapping \ --config-file <path to .config file> Above there is an Example of config file. link:etl_config.txt[role=include]
export NEO4J_HOME=/path/to/neo4j-enterprise-3.4.0 mkdir -p /tmp/northwind $NEO4J_HOME/bin/neo4j-etl generate-metadata-mapping \ --rdbms:url jdbc:oracle:thin:@localhost:49161:XE \ --rdbms:user northwind --rdbms:password northwind \ --rdbms:schema northwind --output-mapping-file /tmp/northwind/mapping.json
Neo4j 4.0 Enterprise has multi-tenancy support, in order to support this feature we added a select options box in the import view as it follows:
If you use the command line tool you can specify the destination database by passing
the --neo4j:database-name
option in this way:
echo '{ "multiline-fields" : "true" }' > /tmp/northwind/options.json $NEO4J_HOME/bin/neo4j-etl export \ --rdbms:url jdbc:oracle:thin:@localhost:49161:XE \ --rdbms:user northwind --rdbms:password northwind \ --rdbms:schema northwind \ --using cypher:direct | cypher:batch | cypher:fromSQL \ --neo4j:url bolt://localhost:7687 \ --neo4j:user neo4j --neo4j:password neo4j \ --neo4j:database-name myDatabase \ --import-tool $NEO4J_HOME/bin \ --csv-directory /tmp/northwind \ --options-file /tmp/northwind/options.json \ --quote '"' --force
Please consider that since the neo4j-admin import
removed the support for json files as source
of the options, we could have problems in case of long command lines derived from db with an high number
of entities involved into the process.
echo '{ "multiline-fields" : "true" }' > /tmp/northwind/options.json $NEO4J_HOME/bin/neo4j-etl export \ --rdbms:url jdbc:oracle:thin:@localhost:49161:XE \ --rdbms:user northwind --rdbms :password northwind \ --rdbms:schema northwind \ --using bulk:neo4j-import \ --import-tool $NEO4J_HOME/bin \ --csv-directory /tmp/northwind \ --options-file /tmp/northwind/options.json \ --quote '"' --force
$NEO4J_HOME/bin/neo4j-shell -path $NEO4J_HOME/data/databases/graph.db/ -c 'MATCH (n) RETURN labels(n), count(*);' +--------------------------+ | labels(n) | count(*) | +--------------------------+ | ["Shipper"] | 3 | | ["Employee"] | 9 | | ["Region"] | 4 | | ["Customer"] | 93 | | ["Territory"] | 53 | | ["Product"] | 77 | | ["Supplier"] | 29 | | ["Order"] | 830 | | ["Category"] | 8 | +--------------------------+ 9 rows
It can be done in 3 modes:
-
'cypher:direct' (LOAD CSV)
-
'cypher:batch' (which creates CSV files in the same way as cypher:direct but it translate them into UNWIND statements instead of LOAD CSV)
-
'cypher:fromSQL' (which translate tabular result data from the RDBMS, without creating CSV files)
In online mode via java-bolt-diver
, in order to allow importing CSV from temporary folder is necessary:
-
enable property
dbms.security.allow_csv_import_from_file_urls
and set it to true in order to allow LOAD CSV to read CSV files from external resource -
remove property
dbms.directories.import=import
or comment it out to prevent Neo4j to search for CSV file into the default import folder
For Neo4j remote instances you must use cypher:batch
import mode
echo '{ "multiline-fields" : "true" }' > /tmp/northwind/options.json $NEO4J_HOME/bin/neo4j-etl export \ --rdbms:url jdbc:oracle:thin:@localhost:49161:XE \ --rdbms:user northwind --rdbms:password northwind \ --rdbms:schema northwind \ --using cypher:direct | cypher:batch | cypher:fromSQL \ --neo4j:url bolt://localhost:7687 \ --neo4j:user neo4j --neo4j:password neo4j \ --import-tool $NEO4J_HOME/bin \ --csv-directory /tmp/northwind \ --options-file /tmp/northwind/options.json \ --quote '"' --force Additional command line options for `cypher:batch` and `cypher:fromSQL` import modes: --unwindBatchSize <value> (Batch size that will be used for unwind data) \ --txBatchSize <value> (Transaction Batch size that will be used for unwind commit) \
$NEO4J_HOME/bin/cypher-shell -a bolt://localhost:7687 -u neo4j -p neo4j 'MATCH (n) RETURN labels(n), count(*);' +--------------------------+ | labels(n) | count(*) | +--------------------------+ | ["Shipper"] | 3 | | ["Employee"] | 9 | | ["Region"] | 4 | | ["Customer"] | 93 | | ["Territory"] | 53 | | ["Product"] | 77 | | ["Supplier"] | 29 | | ["Order"] | 830 | | ["Category"] | 8 | +--------------------------+ 9 rows
This example session is based on the Northwind example dataset.
DDL scripts are available here:
Download, start and configure the docker container with MySQL:
docker pull mysql docker run --name neo4j-etl-mysql -e MYSQL_ROOT_PASSWORD=admin -e MYSQL_DATABASE=northwind -e MYSQL_USER=neo4j -e MYSQL_PASSWORD=neo4j -d -p 3306:3306 mysql:latest docker exec -it neo4j-etl-mysql bash root@eb6f279fdb88:/# mysql -u root -p Enter password: admin Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> grant all privileges on *.* to 'neo4j'@'%' with grant option; Query OK, 0 rows affected (0.00 sec) mysql> quit; Bye root@bf99fbc0d31c:/# exit exit
Load the database via the following sql script: https://raw.githubusercontent.com/neo4j-contrib/neo4j-etl/master/neo4j-etl-it/src/main/resources/scripts/mysql/northwind.sql
export NEO4J_HOME=/path/to/neo4j-enterprise-3.4.0 mkdir -p /tmp/northwind echo '{ "multiline-fields" : "true" }' > /tmp/northwind/options.json ./bin/neo4j-etl export \ --rdbms:url jdbc:mysql://localhost:5433/northwind?autoReconnect=true&useSSL=false \ --rdbms:user neo4j --rdbms:password neo4j \ --import-tool $NEO4J_HOME/bin \ --options-file /tmp/northwind/options.json \ --csv-directory /tmp/northwind \ --destination $NEO4J_HOME/data/databases/graph.db/ \ --quote '"' --force
Download, start and configure the docker container with PostgreSQL 9.6.2:
docker pull postgres docker run --name neo4j-etl-postgres -e POSTGRES_USER=neo4j -e POSTGRES_PASSWORD=neo4j -d -p 5433:5432 postgres docker run -it --rm --link neo4j-etl-postgres:postgres postgres psql -h postgres -U neo4j Password for user neo4j: psql (9.6.2) Type "help" for help. neo4j=# DROP DATABASE IF EXISTS northwind; neo4j=# CREATE DATABASE northwind WITH OWNER 'neo4j' ENCODING 'UTF8' LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8'; neo4j=# \q
Load the database via the following sql script: northwind.sql
export NEO4J_HOME=/path/to/neo4j-enterprise-3.4.0 mkdir -p /tmp/northwind echo '{"multiline-fields":"true"}' > /tmp/northwind/options.json ./bin/neo4j-etl export \ --rdbms:url jdbc:postgresql://localhost:5433/northwind?ssl=false \ --rdbms:user neo4j --rdbms:password neo4j \ --import-tool $NEO4J_HOME/bin \ --options-file /tmp/northwind/options.json \ --csv-directory /tmp/northwind \ --destination $NEO4J_HOME/data/databases/graph.db/ \ --quote '"' --force
Download, start and configure the docker container with Oracle XE 11g:
docker pull wnameless/oracle-xe-11g docker run --name neo4j-etl-oracle -d -p 49160:22 -p 49161:1521 wnameless/oracle-xe-11g ssh root@localhost -p 49160 root@localhost's password: admin Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.9.13-moby x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Last login: Mon May 1 17:32:48 2017 from 172.17.0.1 root@692c446a274b:~# wget https://raw.githubusercontent.com/neo4j-contrib/neo4j-etl/master/neo4j-etl-it/src/main/resources/scripts/oracle/northwind.sql root@692c446a274b:~# sqlplus system/oracle SQL> CREATE USER northwind IDENTIFIED BY northwind; SQL> GRANT DBA TO northwind; SQL> CONN northwind/northwind; SQL> SET sqlblanklines ON; SQL> @northwind.sql SQL> quit; root@692c446a274b:~# exit export NEO4J_HOME=/path/to/neo4j-enterprise-3.4.0 mkdir -p /tmp/northwind echo '{"multiline-fields":"true"}' > /tmp/northwind/options.json ./bin/neo4j-etl export \ --rdbms:url jdbc:oracle:thin:@localhost:49161:XE \ --rdbms:user northwind --rdbms:password northwind \ --rdbms:schema northwind \ --import-tool $NEO4J_HOME/bin \ --options-file /tmp/northwind/options.json \ --csv-directory /tmp/northwind \ --destination $NEO4J_HOME/data/databases/graph.db/ \ --quote '"' --force --driver /tmp/ojdbc6-11.2.0.3.jar
Download, start and configure the docker container with Microsoft SQL Server:
docker run --name neo4j-etl-mssql -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Passw0rd!' -p 1433:1433 -d microsoft/mssql-server-linux
If you want to connect to Microsoft SQL client console then you can run the following command:
docker exec -it neo4j-etl-mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Passw0rd!' -d <DATABASE>
export NEO4J_HOME=/path/to/neo4j-enterprise-3.4.0 mkdir -p /tmp/wideworldimporters echo '{"multiline-fields":"true"}' > /tmp/wideworldimporters/options.json ./bin/neo4j-etl export \ --rdbms:password "Passw0rd!" \ --rdbms:user sa \ --rdbms:url "jdbc:sqlserver://localhost:1433;databaseName=WideWorldImporters" \ --import-tool $NEO4J_HOME/bin \ --options-file /tmp/wideworldimporters/options.json \ --csv-directory /tmp/wideworldimporters \ --destination $NEO4J_HOME/data/databases/graph.db/ \ --driver /tmp/mssql-jdbc-6.1.0.jre8.jar \
# Create docker instance for MS-SQL Server docker run --name mssql-etl \ -e MSSQL_COLLATION=Latin1_General_100_CI_AS \ -e 'ACCEPT_EULA=Y' \ -e 'SA_PASSWORD=<YOUR_PASSWORD>' \ -p 1433:1433 \ -v /tmp:/tmp \ -d microsoft/mssql-server-linux:2017-latest # Download World Wide Importers backup file wget https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak # Create a backup directory sudo docker exec -it mssql-etl mkdir /var/opt/mssql/backup # Load backup file into the container sudo docker cp WideWorldImporters-Full.bak mssql-etl:/var/opt/mssql/backup # Restore Wide World Importers database sudo docker exec -it mssql-etl /opt/mssql-tools/bin/sqlcmd \ -S localhost \ -U SA \ -P '<YOUR_PASSWORD>' \ -Q 'RESTORE FILELISTONLY FROM DISK = "/var/opt/mssql/backup/WideWorldImporters-Full.bak"' \ | tr -s ' ' \ | cut -d ' ' -f 1-2 sudo docker exec -it mssql-etl /opt/mssql-tools/bin/sqlcmd \ -S localhost \ -U SA \ -P '<YOUR_PASSWORD>' \ -Q 'RESTORE DATABASE WideWorldImporters FROM DISK = "/var/opt/mssql/backup/WideWorldImporters-Full.bak" WITH MOVE "WWI_Primary" TO "/var/opt/mssql/data/WideWorldImporters.mdf", MOVE "WWI_UserData" TO "/var/opt/mssql/data/WideWorldImporters_userdata.ndf", MOVE "WWI_Log" TO "/var/opt/mssql/data/WideWorldImporters.ldf", MOVE "WWI_InMemory_Data_1" TO "/var/opt/mssql/data/WideWorldImporters_InMemory_Data_1"'