28

I'm using Linux 16.04 OS. I have installed fresh neo4j. I get referenced exegetic and digitalocean sites.

By default there's graph.db database.

My question is how to create a new database and create nodes and relation ship between nodes?

As I show in picture default DB name is graph.db.

enter image description here

Dhaval
  • 1,393
  • 5
  • 29
  • 55
  • 1
    The instance (unless your in a cluster) is the database. – Matthew Campbell Aug 20 '17 at 16:24
  • Try clicking that "Start Learning" link you see there ... :-) – Tom Geudens Aug 20 '17 at 17:06
  • @Tom that I know but want to create new db with name movie. Does it possible in community edition? If yes than how ? If no than why ? – Dhaval Aug 20 '17 at 17:25
  • @Matthew I didn't understand your thoughts can you explain what is the meaning of " The instance is the database ". – Dhaval Aug 20 '17 at 17:27
  • 2
    Database servers like SQL Server can have multiple database instances. Neo4j doesn't work that way. The process (again unless it is in a cluster) is the database instance. This makes sense when you use clients, they only connect to a URL without using a database name. – Matthew Campbell Aug 20 '17 at 17:33
  • 2
    Stop the instance ... modify the name of the database in the neo4j.conf file. Start the instance again and you'll be running a "new" database. If you've installed with a package it's /etc/neo4j/neo4j.conf, otherwise (with zip) it's [installationdir]/conf/neo4j.conf. – Tom Geudens Aug 20 '17 at 17:35
  • @MatthewCampbell Now got your point and clear my doubt. – Dhaval Aug 20 '17 at 17:37

6 Answers6

27

Since you're using Neo 3.x, to create a new database without removing your existing one, you can simply edit the neo4j.conf file in your conf directory of your $NEO4J_HOME.

Search for dbms.active_database=, which should have the default value of graph.db. Replace it with some other name and start neo4j again. Now, a new database will be created under that directory name. To switch back to your previous db, repeat the steps, just replace your new value with graph.db in the configuration file.

manonthemat
  • 6,101
  • 1
  • 24
  • 49
  • 3
    Don't forget to also **UNCOMMENT** that line you're editing in the neo4j.conf file! Upon initial installation (at least in Neo 3.4.9), it reads _#dbms.active_database=graph.db_ , i.e. commented out by the character # at the beginning – Julian - BrainAnnex.org Dec 28 '18 at 07:49
8

Neo Technology has come with a new Desktop Tool that greatly improves productivity called Neo4J Desktop. You can download it here

Using it you can manage different projects, create different databases, and simply manage them / switch between them, using the GUI. Really saves a lot of time.

enter image description here

Mehdi LAMRANI
  • 11,289
  • 14
  • 88
  • 130
4

Apparently in Community Edition you only have 1 database, so I used docker containers to create one server per db. Modify the ports + data volume as shown below:

docker run \
--rm \
--publish=8474:7474 --publish=8687:7687 \
--volume=$HOME/neo4j/data2:/data \
--volume=$HOME/Downloads/neo4j/import:/var/lib/neo4j/import \
--name=neo4j \
--env NEO4J_AUTH=neo4j/password \
neo4j:3.4


# Defaults:
# --publish=7474:7474 --publish=7687:7687 \
# --volume=$HOME/neo4j/data:/data \
Luke W
  • 8,276
  • 5
  • 44
  • 36
3

In the documentation of Neo4j

Community Edition is a fully functional edition of Neo4j, suitable for single instance deployments. It has full support for key Neo4j features, such as ACID compliance, Cypher, and programming APIs. It is ideal for learning Neo4j, for do-it-yourself projects, and for applications in small workgroups.

So you only have one database instance.

If you want to get started with Neo4j there is a section in the community edition called "jump into code." There is a wizard to tell you how to get started with their language "Cypher."

Aaron
  • 55,518
  • 11
  • 116
  • 132
Abdullah Shahin
  • 1,002
  • 15
  • 19
3

To create a new Neo4j database in Unix Environment, the following steps are needed: first, the configuration file of neo4j exists in the following location: cd /etc/neo4j (ls ---> neo4j.config); access the file using vim: sudo vim neo4j.config; edit the following (by pressing i (for insert)): there is a commented assignment (at the beginning) which is: #dbms.active_database=graph.db; remove the comment and add the name of the folder containing the database that you want to create and directly add its location before graph.db i.e: dbms.active_database=new_db/graph.db; press: Esc + :wq (to save the modification)

After executing sudo service neo4j start, you will see that the activated database is new_db/graph.db if you want to check that everything went fine, follow these steps: go to: cd /var/lib/neo4j; execute: ls (you will have certificates, plugins, data, import); then go to: cd data/databases; then execute ls :you will notice that you have the old database (graph.db), and the new folder new_db that contains also the new_created database graph.db

Remarks:

  1. Neo4j is developed for single database use, and all the manipulations are performed on a single database.
  2. If you want to clear the database, you can go to the location of graph.db and erase everything since doing that from neo4j is very difficult and most of times, you will forget to delete dependencies, labels, ... i.e : say, we want to clear the new created database graph.db that exists in the folder new_db: we go to : cd ..../new_db; execute ls (you will have graph.db); execute: sudo rm -rf graph.db/*;
  3. Last remark, if you want to access the default database, you just recomment the assignment that you edited
Nauman Naeem
  • 408
  • 3
  • 12
J.Khoder
  • 66
  • 4
0

The process is a little tricky in case of causal cluster.

First, stop all the neo4j instances across the VMs in your cluster

sudo systemctl stop neo4j

DB location on Linux machines = /var/lib/neo4j/data/databases To delete existing db : rm -rf /database/graph.db

Edit new DB name under the template Search for dbms.active_database=, which should have the default value of graph.db . Replace it with a new DB. On the restart, neo4j will automatically create it. Remember to UNCOMMENT the line.

Unbind all the nodes — this clears the cluster state and forces the node to freshly join the cluster. neo4j-admin unbind Now, this is really important and most people are unaware of this.

Now go ahead and start neo4j instances in all the nodes one by one. This should create new DBs across and you’ll see the nodes joining the cluster. sudo systemctl start neo4j

Check logs using

journalctl -unit=neo4j -r
OR
sudo systemctl status neo4j