Neo4j导出dump文件操作指南
Neo4j导出dump需先停止服务:4.0以下版本用`neo4j-admindump`,5.0以上用`neo4j-admindatabasedump`。必须以管理员身份运行cmd,否则因权限不足导致数据库名后多空格而报错。
Neo4j导出dump文件
1. 首先需要暂停Neo4j服务
这一步是必须的——数据库在运行时,直接导出dump文件是不被允许的。先停止服务,再执行后续操作。

neo4j stop
2. 进入Neo4j安装目录
找到bin目录,在其中打开命令行窗口。确保路径正确,否则命令无法执行。
3. 版本不同,命令也有差异
网络上大部分资料针对的是4.0以下版本,命令格式如下:
neo4j-admin dump --database=neo4j --to=D:/Backup_graphData/xxxx.db.dump
--database=后面指定要导出的数据库名称--to=后面指定保存文件的完整路径
4. 目前Neo4j已更新至5.0版本
新版本对命令结构进行了调整,导出时需要采用以下格式:
neo4j-admin database dump --to-path="D:/test/" neo4j
--to-path 指定存放目录,neo4j 为数据库名称。
如需查看完整的命令行参数,可直接运行以下命令获取详细说明:
neo4j-admin database dump [-h] [--expand-commands] [--verbose] [--overwrite-destination[=true|false]] [--additional-config=] [--to-path= | --to-stdout] DESCRIPTION Dump a database into a single-file archive. The archive can be used by the load command. should be a directory (in which case a file called .dump will be created), or --to-stdout can be supplied to use standard output. If neither --to-path or --to-stdout is supplied `server.directories.dumps.root` setting will be used as destination. It is not possible to dump a database that is mounted in a running Neo4j server. PARAMETERS Name of the database to dump. Can contain * and for globbing. Note that * and ha ve special meaning in some shells and might need to be escaped or used with quotes. OPTIONS --additional-config= Configuration file with additional configuration. --expand-commands Allow command expansion in config value evaluation. -h, --help Show this help message and exit. --overwrite-destination[=true|false] Overwrite any existing dump file in the destination folder. Default: false --to-path= Destination folder of database dump. --to-stdout Use standard output as destination for database dump. --verbose Enable verbose output.
5. 注意事项
一个容易忽略的问题:务必使用管理员身份打开cmd,否则可能会遇到类似以下的错误:
Invalid value for positional parameter at index 0 (
): Invalid database name 'neo4j '. (ja va.lang.IllegalArgumentException: Database name 'neo4j ' contains illegal characters. Use simple ascii characters, numbers, dots, question marks, asterisk and dashes.)
该错误表面上是在数据库名后多加了一个空格,但本质上是权限不足导致的异常。因此,启动命令行时请右键选择“以管理员身份运行”,可避免许多不必要的麻烦。
总结
不同版本的Neo4j,导出命令有所不同。4.0以下版本使用 neo4j-admin dump,5.0及以上版本使用 neo4j-admin database dump。操作前先停止服务,并以管理员权限打开cmd,这样基本可以顺利完成导出。官方文档是最可靠的参考资料,网上许多信息已经过时,遇到问题直接查阅官方手册最为省心。
