Setting up IDEA

Intellij IDEA knows how to work with databases no worse than Workbench. It even has a dedicated Database tab in the right pane. If you click on it, you will see a picture:

Mysql Connecting Intellij IDEA

Let's try to connect to our database. To get started, click on the plus sign:

Mysql Connecting Intellij IDEA 1

How do you like the list of supported databases? Impressive? Starting from Google Big Query and ending with Cassandra.

Connecting MySQL IDEA

But we are modest people, so we'll just choose MySQL. IDEA immediately suggests specifying the settings for connecting to the database:

Mysql Connecting Intellij IDEA 2

There are even more of them than Workbench. Although everything you need is already indicated, maybe there is no login and password.

From the interesting: IDEA is written in Java, so it uses standard Java drivers to work with MySQL. That is, exactly those that our program will use when it sends queries to the MySQL server.

Therefore, feel free to click Download to download the missing drivers.

I also specified the login and password for our local server and then clicked on the Test Connection button:

Mysql Connecting Intellij IDEA 3

The connection was successfully established, so feel free to click OK.

Displaying the contents of the database

If you see this picture:

Mysql Connecting Intellij IDEA 4

Then click on the place highlighted in red and select the list of schemes manually. I specified 3: test, test2 and supershop and this is what I see now:

Mysql Connecting Intellij IDEA 5

All three of my diagrams are in place. Let's see what we have in the user table:

Mysql Connecting Intellij IDEA 6

Well, I already knew what columns we have there, but how to see the data?

Display table content

I just double clicked on the table name and IDEA showed me this:

Mysql Connecting Intellij IDEA 7

So far, it looks much more interesting than in Workbench. The data was immediately displayed, and besides, there are service fields WHERE and ORDER BY. So that you can filter and sort data right on the spot.

Let's try to sort our table by level...

As soon as I started writing the word level, IDEA immediately offered me a great list of hints:

Mysql Connecting Intellij IDEA 8

Perhaps it looks more interesting than working through Workbench, he didn’t give out any special hints.

I typed level, hit enter, and voila, the table is sorted:

Mysql Connecting Intellij IDEA 9

Okay, now I want to execute an arbitrary query without binding to a table, where can I do it?

We return to the panel on the right - there is a special button there to open the Query Console:

Mysql Connecting Intellij IDEA 10

And we start writing a query:

Mysql Connecting Intellij IDEA 11

Auto tips from IDEA, as always, on top . And here is the result of our query:

undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0516
task0516
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0517
task0517
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0518
task0518
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0519
task0519
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0520
task0520
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0521
task0521
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0522
task0522
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0523
task0523
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0524
task0524
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0525
task0525
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0526
task0526
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0527
task0527
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0528
task0528
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0529
task0529
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0530
task0530
undefined
1
Task
Module 4. Working with databases, level 5, lesson 14
Locked
task0531
task0531