Installation and use of Mac Neo4j graph database

1. Introduction to Neo4j

        Graph database is a NoSQL database implemented based on graph theory. Its data storage structure and data query method are based on graph theory. Graph database is mainly used to store more connected data.

        Neo4j is a well-known graph database that provides Cypher query language.

2. Installation and startup

        Before installation, make sure there are Java 8 runtime files in the Mac system.

2.1 Installation

It is recommended to install through brew and use the following command:

brew install neo4j
-- 安装路径一般为:  /usr/local/opt/neo4j/bin

2.2 Startup

cd bin
./neo4j start  --verbose
./neo4j stop   # 关闭

 2.3 Web access

        After the database is started, log in locally at http://localhost:7474, and the browser can enter neo4j. The initial account password is neo4j.
You can set a new password yourself: 12345678

3. Common operations & data import

3.1 Common operations

3.1.1. Create a node

        Node is a basic element in a graph database, used to represent an entity record, just like a record in a relational database, and can contain multiple properties (Properties) and multiple labels (Label).

create(person:Person{name:"jack", age:18}); 

3.1.2 Query nodes

match(n:Person) 
where n.name='jack' 
return n 
order by n.age 
limit 2  

graphic form

 tabular form

 111

3.1.3 Creating relationships

Establish a relationship between person and dog nodes

match (person:Person), (dog:DOG)
where person.name="jack" and dog.name="buou"
create(person)-[r:R{isOwner:"yes"}]->(dog)
return r

3.2 Data backup & import

Use neo4j to import data:

neo4j-admin import --nodes path_of_nodes_data --relationships path_of_relationship_data

Database backup and restore:

# 数据库备份
neo4j-admin dump --database=graph.db --to=/neo4j/backup/graph_backup.dump
# 数据库还原
neo4j-admin load --database=graph.db --from=/neo4j/backup/graph_backup.dump

Query all nodes and all their neighbor nodes:

MATCH (a)-[:REL]->(b)
RETURN a, b

 

Guess you like

Origin blog.csdn.net/MusicDancing/article/details/132238422