32

Anybody know how to create new database in DataGrip (database IDE from JetBrains)? Could not find in DataGrip Help page.

Abduhafiz
  • 2,711
  • 3
  • 32
  • 44

5 Answers5

25

In DataGrip 2017.1 UI for this was introduced

enter image description here

moscas
  • 6,378
  • 28
  • 35
9

You first define the database. File --> Data Sources and Drivers --> Click on the green '+' in the top left corner to select the database type. And then fill in all the settings in the 'General' tab.

For example for PostgreSQL:

Host: localhost

Database: postgres

User: postgres

Password: password

Once you are set up, Ctrl+Shift+F10 to open the console and you can type your SQL statements, e.g.:

CREATE DATABASE my_database TEMPLATE template1
USER_1
  • 2,096
  • 1
  • 23
  • 27
  • 1
    When I posted this question, there wasn't possibility to create database from DataGrip UI. Anyway, thanks for answer. May be somebody needs it. – Abduhafiz Jun 01 '16 at 11:02
  • 1
    This answer is not relevant, it is about creating a datasource, not database – moscas Mar 31 '17 at 11:25
5

I don't believe the existing answers cover MySQL... In MySQL, creating a new schema is equivalent to creating a new database. For this case, contextual-click (usually right-click) on your connection in the navigation tree and choose New | Schema. Give it a name and 'Execute in database".

The name of this schema will show up in the navigation tree and you can then add tables, data, etc.

HumanJHawkins
  • 198
  • 1
  • 9
3

The tricky part of creating a new database, is that you have to do it using a DataGrip "Data Source" where are are connected as a user that has the priviledge to create a database, which is generally the "admin" user that you added when you first installed Postgres which is connected to the main "postgres" database.

I like to keep track of all the commands I have run by attaching a new directory (File Menu | Attach Directory) and creating new files with descriptive names, such as "create_my_test_db.sql" and enter the sql to create the database:

create database my_test_db;

When you want to execute this code, make sure that you are using the correct "console". DataGrip has a drop-down menu in the upper-right corner above your file menu, so make sure you have selected "postgres@localhost", since this is the user Data Source that has privileges to create a new database.

Similarly, to create a new user for this data base, create a new sql file "create_my_test_db_user.sql"

create user my_test_db_user with encrypted password 'keyboard_cat';
grant all privileges on my_test_db to my_test_db_user;

Then you can create a new Data Source, and set the properties to host = localhost, user = my_test_db_user, and password = keyboard_cat.

Stefan Musarra
  • 1,349
  • 13
  • 16
1

Go to the name of your connection (eg: cat-app@localhost) ,right-click and select Schema. Creating a Schema and Database are same in Mysql.