MySQL 如何将intellij与本地mysql连接?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38660104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:57:01  来源:igfitidea点击:

How to connect intellij with local mysql?

mysqldatabaseintellij-ideaprogrammers-notepad

提问by RAJMOHAN

I have been struggling to learn how the localhost mysql and the intellij to connect and programme a database related task.Is that possible?if yes how it achieve?

我一直在努力学习localhost mysql和intellij如何连接和编程与数据库相关的任务。这可能吗?如果是的话,它是如何实现的?

回答by James Wynn

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.

连接到本地实例本质上与连接到 MySQL 的远程实例相同。只需用 localhost 或 127.0.0.1 代替您通常使用的 IP 地址即可。

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 Sourceand then MySQLfrom the sub-menu. The defaults for the MySQL connection should for a local install of MySQL.

要添加新的数据库连接(在 IntelliJ 中称为数据源),请打开数据库窗口View-> Tool Windows-> Databases,然后单击+号并从子菜单中选择Data SourceMySQL。MySQL 连接的默认值应该用于 MySQL 的本地安装。

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

要打开连接,请右键单击新数据源并选择Open Console

Official IntelliJ Documentation - Managing Data Sources

IntelliJ 官方文档 - 管理数据源

回答by Hyman Doe

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 IDEin **File->Settings->Plugins->Browse repositoriesand 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.

从社区版本 2017.2 开始,DB 浏览器未与IDE(至少在我的最后两次安装中没有)捆绑在一起。为了激活它,您应该在IDEin 中导航**File->Settings->Plugins->Browse repositories"Database"从下拉菜单中选择。您可以从那里安装 Database Navigator。安装成功后,您应该重新启动IDE. 然后就可以选择了**View->Tool windows->DB Browser

回答by sdlins

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].

在 Idea Community 的最新版本(大约 2017.3,但我不确定)中,不再有可用的数据库工具,仅在 Idea Ultimate [1] 中可用。更糟糕的是,适合在这里解决此问题的插件 Database Navigator 不再兼容,至少与 2018.3 [2] 不兼容。

Uninstalling Idea right now, unfortunately.

不幸的是,现在正在卸载 Idea。

[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-

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

[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

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

回答by ARiyou Jahan

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.

要添加新的数据库连接(在 IntelliJ 中称为数据源),请打开数据库窗口视图 -> 工具窗口 -> 数据库,然后单击 + 号并从子菜单中选择数据源和 MySQL。MySQL 连接的默认值应该用于 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 :

如果您想添加 JDBC 并连接其他数据库供应商,如工作台项目(而不是使用 intelliJ Consol),只需按照以下步骤操作:

Using JDBC drivers #

使用 JDBC 驱动程序 #

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.

使用JDBC驱动创建数据库连接#如果在数据源列表中找不到数据库供应商的名称,请下载数据库管理系统(DBMS)的JDBC驱动,并在IntelliJ IDEA中创建连接。使用 JDBC 驱动程序,您可以连接到 DBMS 并开始工作。

  1. In the Databasetool window (View | Tool Windows | Database), click the Data Source Propertiesicon.

  2. In the Data Sources and Driversdialog, click the Addicon (+) and select Driver and Data Source.

  3. Click the User Driverlink.

  4. In the Driver filespane, click the Addicon and select Custom JARs.

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

  6. In the Classfield, 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 URLfield. To set an empty password, right-click the Passwordfield and select Set empty.

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

  1. 数据库工具窗口(查看 | 工具窗口 | 数据库)中,单击数据源属性图标。

  2. 数据源和驱动程序对话框中,单击添加图标 ( +) 并选择驱动程序和数据源

  3. 单击用户驱动程序链接。

  4. Driver files窗格中,单击Add图标并选择Custom JARs

  5. 导航到 JDBC 驱动程序的 JAR 文件,选择它,然后单击 OK

  6. 字段中,指定要用于驱动程序的值。

  7. 点击应用

  8. 返回到创建的数据源连接。

  9. 指定数据库连接详细信息。或者,将 JDBC URL 粘贴到URL字段中。要设置空密码,请右键单击Password字段并选择 Set empty

  10. 为确保与数据源的连接成功,请单击测试连接



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

有关更多信息,请阅读以下链接中 Jetbrains 的官方回答:

Configuring database connections

配置数据库连接

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

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