本文主要是介绍python实现rdbms和neo4j的转换,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
python&neo4j
- 一、连接neo4j
- 二、rdbms转换到neo4j
- 三、常见报错
- <一>、ValueError: The following settings are not supported
一、连接neo4j
- 下载依赖库
pip install py2neo
- 连接neo4j
from py2neo import Graph
graph = Graph("bolt://localhost:7687", auth=("neo4j","neo4j"))
二、rdbms转换到neo4j
- 想了解neo4j的语法可看:neo4j的入门操作
- 转换
import pymysql
from py2neo import Graphdef pymain:#连接Mysqlconn = pymysql.connect(host="localhost",user="test",password="test",port=3309,database="test_db")cursor = conn.cursor()cursor.execute("select deptno,employee from employees")rows = cursor.fetchall()for row in rows:deptno,employee = rowinsert_data2neo4j(deptno,employee)def insert_data2neo4j(deptno,employee): #连接neo4jgraph = Graph("bolt://localhost:7687",auth=("neo4j","neo4j"))graph.run("MERGE (d:deptno {name: $deptno})""MERGE (e:employee {name: $employee})""MERGE (e)-[:BELONGS_TO]->(d)",deptno=deptno,employee=employee)if __name__ == '__main__':pymain()
三、常见报错
<一>、ValueError: The following settings are not supported
- 这是因为py2neo版本更新,不支持下述写法
graph = Graph(host="",user="",password="")
应改为
graph = Graph("bolt://localhost:7687", auth=("neo4j","neo4j"))
这篇关于python实现rdbms和neo4j的转换的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!