neo4j笔记
1. Neo4j介绍
Neo4j是一种NoSQL数据库,而且属于NoSQL数据库里的图数据库。 常见的SQL数据库有MySQL Oracle等 常见的NoSQL数据库有Redis ES Mongdb Neo4j等 近几年比较流行的的图数据库有Neo4j Titan OrientDB Sparksee Virtuso ArangoDb Airaph GraphDB GraphBase等
Neo4j数据库比较适合处理关系,比如人和人之间的关系。 比较成功的应用有 领英 FaceBooke Twitter
2. Neo4j下载、安装、配置
neo4j分为企业版和社区版,社区版免费,企业版收费。
2.1 下载
linux unix 推荐下载.tar.gz包 windows推荐下载.zip包,第一,和linux上目录及文件一样;第二,使用.exe安装的用户经常找不见配置,load csv以及其他操作时经常找不见目录
下载地址: Neo4j所有版本的下载地址
https://neo4j.com/download-thanks/?edition=community&release=3.1.2&flavour=unix Linux Mac版 https://neo4j.com/download-thanks/?edition=community&release=3.1.2&flavour=winzip Windows版
2.2 安装
- 下载的压缩包neo4j-community-3.1.2.zip,解压完就可以用。
- 解压完进入bin目录,输入neo4j console就可以看到neo4j数据库启动了,可以在浏览器里输入http://localhost:7474来访问数据库,默认用户名、密码: neo4j/neo4j
- 如果想自定义配置,可以在${NEO4J_HOME}/conf/neo4j.conf修改对应配置
官网的安装说明
打开终端
1 Open up your terminal/shell.
解压安装包
2 Extract the contents of the archive, using: tar -xf <filecode>.
For example,tar -xf neo4j-community-3.1.2-unix.tar.gz
the top level directory is referred to as NEO4J_HOME
$NEO4J_HOME指安装目录,在neo4j安装目录的bin目录使用neo4j console启动neo4j数据库
3 Run Neo4j using, $NEO4J_HOME/bin/neo4j console
Instead of 'neo4j console', you can use neo4j start to start the server process in the background.
在浏览器里输入http://localhost:7474即可访问数据库
4 Visit http://localhost:7474 in your web browser.
第一次登录数据库默认用户名密码是neo4j/neo4j,第一次登录需要修改密码
5 Change the password for the 'neo4j' account.
linux用户注意: 使用超级用户修改/etc/security/limits.conf文件,允许当前用户(neo4j)打开40000个文件
neo4j soft nofile 40000
neo4j hard nofile 40000
2.3 配置
常用配置
#设置可以通过ip当问Neo4j数据库
dbms.connectors.default_listen_address=0.0.0.0
#历史版本请修改
dbms.connector.http.address=0.0.0.0:7474
org.neo4j.server.webserver.address=0.0.0.0
#(可以不配置)
export NEO4J_HOME=/usr/neo4j/neo4j-community-3.1.2
#启动Neo4j数据库
./${NEO4J_HOME}/bin/neo4j start
#停止数据库
neo4j stop
windows 使用neo4j console来启动数据库
使用nohup命令可以使neo4j数据库一直运行
nohup ./bin/neo4j console = neo4j start
要结束该命令时,用 kill -9 进程号 来关闭该进程
设置neo4j开机启动
vim /etc/rc.d/rc.local
在文件最后添加如下命令行:
/usr/share/neo4j/bin/neo4j start
其中/usr/share/neo4j/bin/是安装Neo4j的路径
3. Neo4j使用
A row is a node A table name is a label name
Properties Both nodes and relationships can have properties. Properties are named values where the name is a string. The supported property values are: • Numeric values, • String values, • Boolean values, • Collections of any other type of value.
Labels have an id space of an int, meaning the maximum number of labels the database can contain is roughly 2 billion.
Paths A path is one or more nodes with connecting relationships, typically retrieved as a query or traversal result
Neo4j is a schema-optional graph database
You can use Neo4j without any schema. Optionally you can introduce it in order to gain performance or modeling benefits. This allows a way of working where the schema does not get in your way until you are at a stage where you want to reap the benefits of having one.
Indexs Performance is gained by creating indexes, which improve the speed of looking up nodes in the database.
Cypher
:help 帮助页面
:schema 查看数据库结构
:schema ls -l :Person
:server change-password // 修改密码
CALL dbms.changePassword("newpassword") // (旧版本)修改密码
:server connect 连接
:play sysinfo 查看系统信息
// List node labels 查询所有的label
CALL db.labels()
// List relationship types 查询所有的type
CALL db.relationshipTypes()
// What is related, and how 查询数据里的节点和关系 类似于 SQL的desc
CALL db.schema()
// List functions
CALL dbms.functions()
// List procedures
CALL dbms.procedures()
CALL dbms.listQueries() ;
CALL dbms.killQuery(queryId);
// 查询一共有多少节点
// Count all nodes
match (n) RETURN count(n)
// 查询一共有多少关系 // 不带方向的话结果是2倍
// Count all relationships
match ()-->() RETURN count(*);
match ()-[r]->() return count(r);
match (a:Person), (b:Person) where a.name = 'zhangsan' and b.name = 'lisi'
merge (a)-[r:RELTYPE]->(b) return r
// 模糊匹配
match (n:Person) where n.name =~ '张.*' return n
// 包含
match (n:Person) where n.name contains '张' return n;
// 去重
match (n:Person) with n.name as name return distinct name;
// Count all nodes 查询一共有多少节点
match (n) RETURN count(n)
// Count all relationships 查询一共有多少关系
match ()-->() RETURN count(*);
// 查询一共有多少种节点
call db.labels();
match (n) return distinct label(n);
// 查询一共有多少关系
call db.relationshipTypes()
// 查询数据库里的所有属性
match (n) unwind keys(n) as allkeys return distinct allkeys;
// 查询关系最多的节点
// 实际使用时,最好对n加个范围,要不然 全图扫描
// 使用with 和 别名,能减少一次count(*)的查询
match (n:Movie)--() with n.title as title, count(*) as count return title, count order by count desc limit 1;
match (n:Movie)-[r]-() with n.tile as title, count(r) as count return title, count order by count desc limit 1;
// 查询孤立节点
match (n) where not (n)--() return id(n);
github例子
https://github.com/neo4j-examples/movies-java-spring-data-neo4j-4
参考 [1] http://neo4j.com/docs/operations-manual/3.1/ [2] https://neo4j.com/docs/developer-manual/3.1/ [3] http://neo4j.com/docs/2.2.9/query-delete.html [4] https://neo4j.com/docs/developer-manual/3.1/cypher/ [5] https://neo4j.com/blog/neo4j-3-1-ga-release/?ref=home [6] https://neo4j.com/docs/developer-manual/3.1/cypher/clauses/set/ [7] https://neo4j.com/docs/operations-manual/3.2/installation/linux/debian/#multiple-java-versions [8] https://neo4j.com/docs/operations-manual/current/installation/windows/
[9] http://neo4j.com/docs/developer-manual/current/extending-neo4j/procedures/
[10] https://neo4j.com/developer/guide-importing-data-and-etl/ 使用ETL方式导入Neo4j
[11] https://neo4j.com/developer/guide-import-csv/ 使用csv文件方式导入Neo4j
本文转自 http://weikeqin.cn/2017/03/17/neo4j-notes/
原文地址:https://www.cnblogs.com/sea520/p/11847249.html
- layui动态设置下拉框数据,根据后台数据设置选中
- BCryptPasswordEncoder加密及判断密码是否相同
- 两个HTML,CSS布局实例
- cors解决Web跨域访问问题
- Java之集合初探(二)Iterator(迭代器),collections,打包/解包(装箱拆箱),泛型(Generic),comparable接口
- IIS中实现HTTPS的自动跳转
- Windows Server下IIS安装PHP+MySql环境
- Python玩机器学习简易教程
- 腾讯云服务器搭建个人博客教程
- Ubuntu下安装Nginx+PHP+MySql环境
- JavaScript 对象
- HTML 表单
- HTML DOM
- HTML 标签
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Auto Remove Torrents:自动删种程序部署
- OpenVZ平台Alpine Linux一键安装脚本
- 使用holder.js生成美观的网页占位图
- Android studio 3.5.2安装图文教程详解
- Android面试必备的JVM虚拟机制详解,看完之后简历上多一个技能!
- 如何在PHP中JSON在线解析
- Linux下如何克隆磁盘/分区命令dd入门
- Android自定义跑马灯文字效果
- Android实现图片自动切换功能(实例代码详解)
- Android Studio 3.6 正式版终于发布了,快来围观
- android使用ViewPager实现图片自动切换
- Android Studio 3.6 调试 smali的全过程
- Android 10 适配攻略小结
- Android P实现静默安装的方法示例(官方Demo)
- Android studio实现滑动开关