37

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

1
  • It's not possible; there is no UI for this. Sep 20, 2020 at 7:42

5 Answers 5

26

In DataGrip 2017.1 UI for this was introduced

enter image description here

2
  • 9
    This option doesn't seem to be showing up for mysql databases, but shows up for sql server.
    – Shahzad
    May 11, 2017 at 11:20
  • 4
    MySQL supports only one database per instance, right? You can create schemas in MySQL.
    – moscas
    May 12, 2017 at 7:11
10

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
2
  • 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 1, 2016 at 11:02
  • 2
    This answer is not relevant, it is about creating a datasource, not database
    – moscas
    Mar 31, 2017 at 11:25
7

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.

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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.