从mysql中导出数据存储为csv文件
select * from table where options
into outfile 'path' fields terminated by ',' optionally enclosed by '"' lines terminated by '\r\n' ;
into outfile:指定导出的目录和文件名
fields terminated by:存储为文件的时候 定义字段间的分隔符
optionally enclosed by:定义包围字段的字符 (数值型字段无效,不会被添加包围字符)
lines terminated by:定义行间分隔符
示例:
select id,name,gender from students where id > 100 into outfile '/home/Desktop/test.csv'
fields terminated by '\t' optionally enclosed by '"' lines terminated by '\r\n'
neo4j 数据库读取csv文件
读取但不存入数据库
查看csv文件行数
load csv from "path" as line return count(line)
查看csv文件的前5行
load csv from "path" as line with line return line limit 5
查看csv文件带有头信息的前5行
load csv with headers from "path" as line with line return line limit 5
上面语句的path可以是本地文件的路径,也可以是网上文件的url
如果把文件放在neo4j系统路径下的import文件夹内,就不需要指定路径,直接指定文件名即可
读取并存入数据库,需要用到create语句
load csv from '/home/Desktop/test.csv' as line create(:Student {name:line[1],gender:line[2]})
match(n) return n 查看所有创建的节点
导入数据量很大的csv文件使用periodic commit 减少内存开销
periodic commit 指示Neo4j在执行完一定行数后提交数据再继续
默认执行1000行,即每1000行提交一次
使用默认的1000行提交一次
using periodic commit
load csv from '/home/Desktop/test.csv' as line create(:Student {name:line[1],gender:line[2]})
自定义执行次数
using periodic commit 800
load csv from '/home/Desktop/test.csv' as line create(:Student {name:line[1],gender:line[2]})