Neo4j问题及解决

报错1:The client is unauthorized due to authentication failure.

报错2:WARN  Failed authentication attempt for 'neo4j' from 127.0.0.1

  1. 进入neo4j安装目录, 并进入bin目录;
  2. 运行./cypher-shell命令, 输入用户名,密码(初始默认用户名和密码为neo4j)

3.停止neo4j服务,并且删除data/dbms/auth

4.修改D:\neo4j-community-3.5.14\conf下的neo4j.conf配置文件,取消验证机制,修改如下:

dbms.security.auth_enabled=false

5.cmd重启:

C:\Users\kinvy>neo4j.bat console
2020-10-12 02:25:49.576+0000 INFO  ======== Neo4j 3.5.14 ========
2020-10-12 02:25:49.607+0000 INFO  Starting...
2020-10-12 02:26:05.881+0000 INFO  Bolt enabled on 127.0.0.1:7687.
2020-10-12 02:26:08.717+0000 INFO  Started.
2020-10-12 02:26:10.148+0000 INFO  Remote interface available at http://localhost:7474/

6.测试:

这样就可以使用py2neo了

借用案例:

# coding:utf-8
#需要先 cmd 启动:neo4j.bat console
from py2neo import Graph, Node, Relationship

# 连接neo4j数据库,输入地址、用户名、密码
graph = Graph('http://localhost:7474', username='neo4j', password='neo4j')
graph.delete_all()

# 创建结点
test_node_1 = Node('ru_yi_zhuan', name='皇帝')  # 修改的部分
test_node_2 = Node('ru_yi_zhuan', name='皇后')  # 修改的部分
test_node_3 = Node('ru_yi_zhuan', name='公主')  # 修改的部分
test_node_4 = Node('ru_yi_zhuan', name='太监')  # 修改的部分

graph.create(test_node_1)
graph.create(test_node_2)
graph.create(test_node_3)
graph.create(test_node_4)


# 创建关系
# 分别建立了test_node_1指向test_node_2和test_node_2指向test_node_1两条关系,关系的类型为"丈夫、妻子",两条关系都有属性count,且值为1。

#夫妻关系
node_1_zhangfu_node_2 = Relationship(test_node_1, '丈夫', test_node_2)
node_1_zhangfu_node_2['count'] = 1

node_2_qizi_node_1 = Relationship(test_node_2, '妻子', test_node_1)
node_2_qizi_node_1['count'] = 1

#母女关系
node_2_muqin_node_3 = Relationship(test_node_2, '母亲', test_node_3)
node_2_muqin_node_3['count'] = 2

node_3_nver_node_2 = Relationship(test_node_3, '女儿', test_node_2)
node_3_nver_node_2['count'] = 2

#主仆关系
node_1_zhuzi_node_4 = Relationship(test_node_1, '主子', test_node_4)
node_1_zhuzi_node_4['count'] = 3

node_4_nucai_node_1 = Relationship(test_node_4, '奴才', test_node_1)
node_4_nucai_node_1['count'] = 3


#创建关系
graph.create(node_1_zhangfu_node_2)
graph.create(node_2_qizi_node_1)

graph.create(node_2_muqin_node_3)
graph.create(node_3_nver_node_2)

graph.create(node_1_zhuzi_node_4)
graph.create(node_4_nucai_node_1)


print(graph)
print(test_node_1)
print(test_node_2)
print(node_1_zhangfu_node_2)
print(node_2_qizi_node_1)

猜你喜欢

转载自blog.csdn.net/sinat_33846443/article/details/109023259
今日推荐