Docker部署Neo4j 3.5.x跨服务器迁移及4.0版本适配问题咨询
Great question—let’s break down why your direct copy approach failed first, then walk through two reliable migration methods for moving from Neo4j 3.5.x (Docker) to 4.0 on a new server, including the Cypher export/import method you asked about.
- Neo4j 4.0 changed the default database name from
graph.dbtoneo4j—so your copied data wasn’t being loaded as the active database. - The storage engine format changed between 3.5 and 4.0; raw data directory copies aren’t compatible across these major versions.
- The auth prompt issue happens because 4.0 handles authentication differently, and your misaligned data directory caused the
NEO4J_AUTH=noneenv var to be ignored. - The WebSocket error? You mapped port 3003 to 3003 in your Docker run command, but Neo4j’s Bolt protocol (used for WebSocket connections) runs on port 7687 by default. That mismatch broke the connection.
1. Neo4j Admin Dump & Load (Official, Best for Large Datasets)
This is the most reliable method for cross-server and cross-version migrations—it preserves all data, indexes, and constraints efficiently.
Step 1: Export from Your 3.5.x Server
- Stop your running Neo4j 3.5 container:
sudo docker stop vis - Create a dump of your
graph.dbdatabase using the Neo4j 3.5 image:
Replacesudo docker run --rm -v /path/to/your/3.5/data:/data neo4j:3.5 neo4j-admin dump --database=graph.db --to=/data/neo4j_migration_dump.dump/path/to/your/3.5/datawith the actual path to your 3.5 data directory on the source server.
Step 2: Transfer the Dump to the Target Server
Use scp or your preferred file transfer tool to send the dump file:
scp /path/to/your/3.5/data/neo4j_migration_dump.dump your-user@target-server-ip:/path/to/target/dump/
Step 3: Load the Dump into Neo4j 4.0
- On the target server, make sure no Neo4j 4.0 container is running.
- Load the dump into the default 4.0 database (
neo4j):
Thesudo docker run --rm -v /path/to/your/4.0/data:/data neo4j:4.0 neo4j-admin load --database=neo4j --from=/data/neo4j_migration_dump.dump --force--forceflag overwrites the default emptyneo4jdatabase.
Step 4: Start the Neo4j 4.0 Container Correctly
Fix the port mapping for Bolt and ensure auth is disabled:
sudo docker run --name vis-neo4j4 --restart unless-stopped --log-opt max-size=50m --log-opt max-file=10 \ -p 3001:7474 -p 3002:7473 -p 3003:7687 \ -d -v /path/to/your/4.0/data:/data -v /path/to/your/4.0/conf:/conf -v /path/to/your/4.0/logs:/logs \ --env NEO4J_AUTH=none neo4j:4.0
Note: We mapped port 3003 to 7687 (Bolt’s default port) to fix your WebSocket error.
2. Cypher Export & Import (Good for Small/Medium Datasets)
The method you referenced works well if you need to modify data during migration, or have a smaller dataset. Here’s how to implement it:
Step 1: Prepare the Source 3.5.x Server
- Start your 3.5 container and install the APOC plugin (required for bulk export). Download the compatible APOC version for Neo4j 3.5, place it in your plugins directory, and update
neo4j.confto allow unrestricted APOC procedures:dbms.security.procedures.unrestricted=apoc.* - Restart the container, then open the Neo4j browser (or use
cypher-shell) and run this command to export all data to a Cypher file:CALL apoc.export.cypher.all("all_neo4j_data.cypher", {format: "cypher", useOptimizations: {type: "UNWIND_BATCH", unwindBatchSize: 1000}}) - Copy the
all_neo4j_data.cypherfile from your data directory to the target server.
Step 2: Import into Neo4j 4.0
- Start your 4.0 container with
NEO4J_AUTH=none(as in the dump/load method). - Install the compatible APOC version for Neo4j 4.0 if needed, or use
cypher-shellto run the import script:sudo docker exec -it vis-neo4j4 cypher-shell -u neo4j -p "" -f /path/to/all_neo4j_data.cypher
- Always back up your data before starting any migration.
- For large datasets, stick with the
neo4j-admindump/load method—it’s faster and avoids potential Cypher import errors. - If you still run into auth issues after migration, check your
neo4j.conffile to ensuredbms.security.auth_enabled=falseis set (since you’re usingNEO4J_AUTH=none).
内容的提问来源于stack exchange,提问作者canbax

