How to run 'mysql' file?



In CircleCI 1.0, we used to have this code:

  - mysql

      - mysql -u ubuntu circle_test < scripts/db/mysql_setup.sql

Now we are migrating to 2.0 and mysql is a docker instead of a service:

version: 2
      - image: circleci/openjdk:8-jdk
      - image: redis:3.2.11
      - image: donilan/mysql-utf8mb4

We need to prepare our database, how can I execute this mysql -u ubuntu circle_test < scripts/db/mysql_setup.sql when mysql is dockerized?


The same way. You’ll need to define the host as to use TCP instead of a Unix socket.

You will also need to install the mysql-client package or the command won’t be available.


Rohara, thank you very much for the answer. But I’m not sure I completely understand. What host do you mean? Is it mysql -h localhost -P 3306 --protocol=tcp?

Shall the mysql-client form a part of Dockerfile OR shall it be a selfcontained Docker?

I’m going to try this:

version: 2
      - image: arey/mysql-client

      - run: mysql -u ubuntu circle_test < scripts/db/mysql_setup.sql


Sorry for not being more clear.

mysql  -h -u ubuntu circle_test < scripts/db/mysql_setup.sql

Just include this at the top of your job in config.yml

- run: sudo apt install mysql-client

Or if you do want to build an image (it’s never a bad idea in my opinion), here is your Dockerfile:

FROM circleci/openjdk:8-jdk
RUN sudo bash -c "apt-get update && apt-get install -y mysql-client"

You can not access binaries in other containers like in your example. We presently only support running commands in the primary container.

Also, I have heard some reports of that Redis version being a bit sluggish. I have had great success with redis:2.8.19 if you do see any performance issues.


Haha, no problem. I was trying to connect it to dockerized version of mysql-client. I ended up initiating the db from a gradle task. :slight_smile:

Thank you anyways. I will rewrite it.


I’ve tried your solution. But it didn’t work in the end… I could never connect to db. I tried with a docker locally and it was working but not on CircleCi. I tested with and mysql -u root < ...sql.


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.