Creating new database in DataGrip JetBrains

2019-06-14 23:40发布

问题:

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

回答1:

In DataGrip 2017.1 UI for this was introduced



回答2:

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


回答3:

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.



回答4:

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.



回答5:

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.