RAJMOHAN
RAJMOHAN

Reputation: 515

How to connect IntelliJ with local MySQL?

I have been struggling to learn how the localhost MySQL and IntelliJ to connect and program a database related task. Is that Possible? If yes, how to achieve it?

Upvotes: 32

Views: 123467

Answers (6)

don
don

Reputation: 134

For anyone who is having trouble connecting IntelliJ Community Edition with MySQL in 2021. (In IntelliJ Ultimate Database connectivity is supported by default and you can follow the steps shown in the previous answers. However IntelliJ Community Edition does not support it by Default).

Here is what you have to do:

  1. Install "Database Navigator" Plugin. (Settings->Plugins->Marketplace->Search Database Navigator and install)
  2. Open DB Browser Tab (next to the button that opens/closes Project Window) -> Click Options logo -> '+' -> Fill the Database fields (Name, host, Port, DB Name, User and Password).
  3. Download the MySQL Java Connector by searching google for 'java connector mysql'.
  4. Go to File-> Project Structure -> Modules-> Dependencies. Click the '+' on the right side and select 'JARs or directories'. Navigate and find the Java connector you just downloaded (the file looks like this: mysql-connector-java-8.0.26.jar). Click apply and in the project window, under External Libraries, you will see the .jar file.

Upvotes: 2

For WebStorm you need plugin "database-navigator" https://plugins.jetbrains.com/plugin/1800-database-navigator

Upvotes: 0

ARiyou Jahan
ARiyou Jahan

Reputation: 1039

To add a new database connection (called a data source in IntelliJ), open the Database window View -> Tool Windows -> Databases, then click the + sign and select Data Source and then MySQL from the sub-menu. The defaults for the MySQL connection should for a local install of MySQL.

To open a connection, right click on your new data source and select Open Console.

to download Drivers click on "Download missing Drivers" in bottom of the window.


if you want to add JDBC and connect other database vendor like workbench projects (instead of using intelliJ Consol) just follow the steps bellow :

Using JDBC drivers #

Create a connection to a database with a JDBC driver # If you cannot find a name of a database vendor in the list of data sources, download a JDBC driver for the database management system (DBMS), and create a connection in IntelliJ IDEA. With the JDBC driver, you can connect to DBMS and start working.

  1. In the Database tool window (View | Tool Windows | Database), click the Data Source Properties icon.

  2. In the Data Sources and Drivers dialog, click the Add icon (+) and select Driver and Data Source.

  3. Click the User Driver link.

  4. In the Driver files pane, click the Add icon and select Custom JARs.

  5. Navigate to the JAR file of the JDBC driver, select it, and click OK.

  6. In the Class field, specify the value that you want to use for the driver.

  7. Click Apply.

  8. Return to the created data source connection.

  9. Specify database connection details. Alternatively, paste the JDBC URL in the URL field. To set an empty password, right-click the Password field and select Set empty.

  10. To ensure that the connection to the data source is successful, click Test Connection.


For more information read the official answer of Jetbrains in following link :

Configuring database connections

https://www.jetbrains.com/help/idea/configuring-database-connections.html#Configuring_database_connections.xml

Upvotes: 2

sdlins
sdlins

Reputation: 2295

In recent versions of Idea Community (about 2017.3, but I am not sure) there is no Database tool available anymore, only in Idea Ultimate [1]. Yet worse, the plugin Database Navigator that would fit here to solve this problem is not compatible anymore, at least not with 2018.3 [2].

Uninstalling Idea right now, unfortunately.

[1] https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000411990-Database-option-not-available-under-View-Tool-Windows-in-Intellij-v2018-1-Community-Edition-

[2] https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001759260-Dan-Cioacas-Database-Navigator-plugin-v3-0-8222-0-is-incompatible-with-latest-IntelliJ-IDEA-2018-3

Upvotes: 3

Jack Doe
Jack Doe

Reputation: 514

As of Community version 2017.2, the DB Browser does not come bundled with the IDE (at least not on my last two installations). In order to activate it, you should navigate in the IDE in **File->Settings->Plugins->Browse repositories and select "Database" from the dropdown menu. From there you can install the Database Navigator. After the installation has been successful, you should restart the IDE. Then you can select **View->Tool windows->DB Browser.

Upvotes: 35

James Wynn
James Wynn

Reputation: 686

Connecting to a local instance is essentially the same as connecting to a remote instance of MySQL. Just substitute either localhost, or 127.0.0.1 in place of the IP address you would use normally.

To add a new database connection (called a data source in IntelliJ), open the Database window View -> Tool Windows -> Databases, then click the + sign and select Data Source and then MySQL from the sub-menu. The defaults for the MySQL connection should for a local install of MySQL.

To open a connection, right click on your new data source and select Open Console.

Official IntelliJ Documentation - Managing Data Sources

Upvotes: 47

Related Questions