无法通过DataGrip应用程序连接到MySQL docker实例

我已经成功地通过mysql命令行工具连接到一个运行MySQL的docker实例。 不过,我正在努力通过JetBrains的DataGrip应用程序来做到这一点。

我的mysql cli命令如下:

mysql -h127.0.0.1 --port=8181 -uroot 

在DataGrip中生成的连接string是:

 jdbc:mysql://127.0.0.1:8181 

我从DataGrip接口得到的错误是:

 [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up. 

DataGrip中是否有任何需要更改的内容? 我已经读过,连接也必须通过TCP完成。 不知道如何检查DataGrip是这样做的。

更新:我最终发现问题是我正在使用的docker集装箱。 看来DataGrip不能连接到版本8.0.1(mysql:8.0.1)的mysql docker容器。 我testing使用容器的版本5.7,并可以成功连接。

莱昂,

我有一个连接MySQL 8.0.3到DataGrip的问题。 您需要从Oracle 网站下载JDBC驱动程序。 select开发人员发布(因为这是一个不稳定的版本)。 8.0.8版本为我工作。 下载并保存在您的计算机上的项目文件夹或类似的东西。 你以后会需要的。

  • 转到DataGrip:文件>数据源。 点击+并selectDriver
  • 上面的步骤的屏幕截图
  • 在“ Driver Files >“ Additional files ”部分,单击+并select刚才下载的jar文件
  • 之后,在Class下拉列表中selectcom.mysql.jdbc.Driver
  • Dialect标记为MySQL
  • 在部分URL模板上,将Name设置default ,将Template设置jdbc:mysql://{host::localhost}?[:{port::3306}][/{database}?][\?<&,user={user},password={password},{:identifier}={:identifier}>]
  • 点击应用

完成!

在Datagrip上运行的MySQL 8.0.3的屏幕截图

使用新的驱动程序添加新的数据源。

如果您发现以下错误:

 [01S00] The server time zone value 'PDT' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support 

作为一个例子,你可以做一个临时修复,进入Advanced选项卡并设置UTCserverTimezonevariables。