Cannot connect to MySQL docker instance via DataGrip application

connection, datagrip, docker, mysql

Solution

I was having an issue connecting MySQL 8.0.3 using DataGrip. You need to download the JDBC driver from Oracle website. Select Developer Releases (Since this is an unstable version). The 8.0.8 version worked for me. Download and save in a project folder or something similar on your computer. You will gonna need it later.

- Go to DataGrip: File > DataSources. Click on the `+` and select `Driver`:

- Screenshot of the Step above

- On the section `Driver Files` > `Additional files` click on the `+` and select the `jar` file you just downloaded

- After that on the `Class` dropdown select `com.mysql.jdbc.Driver`

- Mark `Dialect` as `MySQL`

- On the section URL templates, put the Name as `default` and Template as `jdbc:mysql://{host::localhost}?[:{port::3306}][/{database}?][\?<&,user={user},password={password},{:identifier}={:identifier}>]`

- Click on apply

Done!

Screenshot of MySQL 8.0.3 running on Datagrip

Add a new datasource using the new driver.

If you find the following error:

[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

You can do a temporary fix going to the `Advanced` tab and setting the `serverTimezone` variable for `UTC` as an example.

Problem

I have managed to successfully connect to a docker instance running MySQL via the mysql command line utility. However, I am struggling to do so via DataGrip application from JetBrains. My mysql cli command is as follows: ``` mysql -h127.0.0.1 --port=8181 -uroot ``` The connection string that is generated in DataGrip is: ``` jdbc:mysql://127.0.0.1:8181 ``` The error I am getting from DataGrip interface is: ``` [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up. ``` Is there anything that need to change in DataGrip that I am missing. I have read that the connection has to also be done via TCP. Not sure how to check that DataGrip is doing that. Update: I eventually found the problem was the docker container I was using. It seems DataGrip is not able to connect to version 8.0.1 (mysql:8.0.1) mysql docker container. I tested using version 5.7 of the container and could successfully connect.

Original source