知识与图谱

Cypher-shell

2022-05-23  本文已影响0人  王十三

Cypher-shell

今天帮人解决一个问题,要把命令写成cypher脚本,好家伙,学了这么久neo4j,还没用过cypher脚本。开始必应:

[Toc]

1 cypher脚本

2 cypher-shell

官方手册Cypher Shell - Operations Manual (neo4j.com)一般比较靠谱:

1. About Cypher Shell CLI

Cypher Shell is a command-line tool that comes with the Neo4j distribution. It can also be downloaded from Neo4j Download Center and installed separately.

Cypher Shell CLI is used to run queries and perform administrative tasks against a Neo4j instance. By default, the shell is interactive, but you can also use it for scripting, by passing cypher directly on the command line or by piping a file with cypher statements (requires PowerShell on Windows). It communicates via the Bolt protocol.

Cypher Shell是Neo4j发行版附带的一个命令行工具。也可以从Neo4j Download Center下载并单独安装。Cypher Shell CLI用于对Neo4j实例运行查询和执行管理任务。默认情况下,shell是交互式的,但是您也可以将它用于脚本编写,方法是直接在命令行上传递cypher,或者使用cypher语句连接到文件(在Windows上需要PowerShell)。它通过Bolt协议进行通信。

6. Running Cypher statements

You can run Cypher statements in the following ways:

  • Typing Cypher statements directly into the interactive shell.
  • Running Cypher statements from a file with the interactive shell.
  • Running Cypher statements from a file as a cypher-shell argument.

您可以通过以下方式运行Cypher语句:

  • 直接在交互式shell中输入Cypher语句。
  • 使用交互式shell从文件运行Cypher语句。
  • 从文件中作为密码shell参数运行Cypher语句。

cypher shell 是neo4j出的一个终端,可以直接运行cypher命令,也可以执行cypher脚本,还可以通过其他终端以运行cypher-shell命令的方式,运行cypher命令(有点绕)。

下面看看如何运行

3 cypher shell运行cypher

3.1 安装cypher-shell

在安装过程中,发现,其实更早还有一个neo4j-shell,不过在3.0版本后就不支持了.

From Neo4j 3.0 access to neo4j-shell is no longer possible from the desktop-installers for Windows and OSX.

To use neo4j-shell, you have to download the TAR/ZIP distribution from: http://neo4j.com/download/other-releases/

3.2 运行

Ⅰ 直接运行

直接在power shell输入命令,显示如下:

PS C:\Users\w> cypher-shell
Unable to connect to localhost:7687, ensure the database is running and that there is a working network connection to it

看样子要先启动neo4j,启动后再输入cypher-shell,成功启动:

PS C:\Users\w> cypher-shell
username: neo4j
password: ************
Connected to Neo4j 4.0.11 at neo4j://localhost:7687 as user neo4j.
Type :help for a list of available commands or :exit to exit the shell.
Note that Cypher queries must end with a semicolon.
neo4j@jobgraph.db>

运行cypher命令试一下:

neo4j@jobgraph.db> CREATE (:Person {name : 'Dick Grayson'});
0 rows available after 71 ms, consumed after another 0 ms
Added 1 nodes, Set 1 properties, Added 1 labels
neo4j@jobgraph.db> MATCH (n:Person) RETURN n;
+-----------------------------------+
| n                                 |
+-----------------------------------+
| (:Person {name: "John", age: 30}) |
| (:Person {name: "John", age: 30}) |
| (:Person {name: "John", age: 30}) |
| (:Person {name: "Dick Grayson"})  |
+-----------------------------------+

4 rows available after 84 ms, consumed after another 0 ms

注意:跟browser不同的是,这里cypher命令之后一定要加分号;否则无法运行,只能换行!!!

Ⅱ 运行cypher脚本:

退出cypher-shell:

neo4j@jobgraph.db> :exit

Bye!
PS C:\Users\w>

Ⅲ 用powershell运行cypher脚本:

4 参考链接

上一篇 下一篇

猜你喜欢

热点阅读