Fra*_*Boi 4 csv terminal neo4j cypher cypher-shell
我有一个密码脚本文件,我想直接运行它。
据我所知,我可以在 SO 上找到的所有答案都使用neo4j-shell在我的版本(Neo4j 服务器 3.5.5)中似乎已弃用并替换为命令的命令cyphershell。
使用命令sudo ./neo4j-community-3.5.5/bin/cypher-shell --help我得到了以下说明。
用法:cypher-shell [-h] [-a ADDRESS] [-u USERNAME] [-p PASSWORD] [--encryption {true,false}] [--format {auto,verbose,plain}] [--debug ] [--non-interactive] [--sample-rows SAMPLE-ROWS] [--wrap {true,false}] [-v] [--driver-version] [--fail-fast | --fail-at-end] [密码]
一个命令行 shell,您可以在其中对 Neo4j 的实例执行 Cypher。默认情况下,shell 是交互式的,但您可以通过直接在命令行上传递 cypher 或通过管道传递带有 cypher 语句的文件(在 Windows 上需要 Powershell)来使用它来编写脚本。
我的文件是以下尝试从 csv 文件创建图形的文件,它来自“图形算法”一书。
WITH "https://github.com/neo4j-graph-analytics/book/raw/master/data" AS base
WITH base + "transport-nodes.csv" AS uri
LOAD CSV WITH HEADERS FROM uri AS row
MERGE (place:Place {id:row.id})
SET place.latitude = toFloat(row.latitude),
place.longitude = toFloat(row.latitude),
place.population = toInteger(row.population)
WITH "https://github.com/neo4j-graph-analytics/book/raw/master/data/" AS base
WITH base + "transport-relationships.csv" AS uri
LOAD CSV WITH HEADERS FROM uri AS row
MATCH (origin:Place {id: row.src})
MATCH (destination:Place {id: row.dst})
MERGE (origin)-[:EROAD {distance: toInteger(row.cost)}]->(destination)
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下命令直接传递文件时:
sudo ./neo4j-community-3.5.5/bin/cypher-shell neo_4.cypher
Run Code Online (Sandbox Code Playgroud)
首先它要求输入用户名和密码,但在输入正确的密码后(错误的密码导致错误The client is unauthorized due to authentication failure.),我收到错误消息:
Invalid input 'n': expected <init> (line 1, column 1 (offset: 0))
"neo_4.cypher"
^
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下命令进行管道传输时:
sudo cat neo_4.cypher| sudo ./neo4j-community-3.5.5/bin/cypher-shell -u usr -p 'pwd'
Run Code Online (Sandbox Code Playgroud)
没有输出生成,也没有图表。
如何使用 neo4j 命令运行密码脚本文件cypher-shell?
我认为关键就在这里:
cypher-shell -- help
... Stuff deleted
positional arguments:
cypher an optional string of cypher to execute and then exit
Run Code Online (Sandbox Code Playgroud)
这意味着参数是实际的密码,而不是文件名。因此,这有效:
cypher-shell -- help
... Stuff deleted
positional arguments:
cypher an optional string of cypher to execute and then exit
Run Code Online (Sandbox Code Playgroud)
但这不是(因为文本“neo_4.cypher”不是有效的密码查询)
GMc@linux-ihon:~> cypher-shell "match(n) return n;"
username: neo4j
password: ****
+-----------------------------+
| n |
+-----------------------------+
| (:Job {jobName: "Job01"}) |
| (:Job {jobName: "Job02"}) |
Run Code Online (Sandbox Code Playgroud)
帮助里还说:
cypher-shell neo_4.cypher
Run Code Online (Sandbox Code Playgroud)
所以:
example of piping a file:
cat some-cypher.txt | cypher-shell
Run Code Online (Sandbox Code Playgroud)
应该管用。可能你的问题都是 sudo 的。特别是猫... | sudo 密码外壳。sudo 可能会保护 cypher-shell 免受某些任意输入的影响(尽管在我的系统上似乎没有这样做)。
如果您确实需要使用 sudo 来运行 cypher,请尝试使用以下命令:
cat neo_4.cypher | cypher-shell
Run Code Online (Sandbox Code Playgroud)
哦,另外,您的脚本没有返回,因此它可能不会显示任何数据,但您仍然应该看到加载的记录的摘要报告。
也许首先尝试一些更简单的方法,例如在脚本中进行简单的 match ... return ... 查询。
哦,不要忘记用分号终止密码查询!