Failing build Ruby mysql2 error


My CircleCI builds are failing intermittently with the following error:

If I rebuild without cache for the individual builds, they succeed. However it fails pretty frequently when new builds are created and it is frustrating to have to manually re-build every time. I’ve also included my config below.

Failing command: bundle exec rake db:create 
Exit code: 1 
rake aborted!
LoadError: cannot open shared object file: No such file or directory - /home/circleci/parting-pro/vendor/bundle/ruby/2.4.0/gems/mysql2-0.4.8/lib/mysql2/
/home/circleci/parting-pro/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/home/circleci/parting-pro/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `block in require'
/home/circleci/parting-pro/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:258:in `load_dependency'
/home/circleci/parting-pro/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/home/circleci/parting-pro/vendor/bundle/ruby/2.4.0/gems/mysql2-0.4.8/lib/mysql2.rb:31:in `<top (required)>'
/home/circleci/parting-pro/config/application.rb:7:in `<top (required)>'
/home/circleci/parting-pro/Rakefile:4:in `require_relative'
/home/circleci/parting-pro/Rakefile:4:in `<top (required)>'
/home/circleci/parting-pro/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
(See full trace by running task with --trace)
Exited with code 1
# Ruby CircleCI 2.0 configuration file
# Check for more details
version: 2
      # specify the version you desire here
      - image: circleci/ruby:2.4.4-node-browsers
      - image: library/mysql:5.7.19
      - image: redis

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at
      # - image: circleci/postgres:9.4

    working_directory: ~/removed

      - checkout

      # Download and cache dependencies
      - restore_cache:
          - v1-dependencies-{{ checksum "Gemfile.lock" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run:
          name: install dependencies
          command: |
            bundle install --jobs=4 --retry=3 --path vendor/bundle

      - save_cache:
            - ./vendor/bundle
          key: v1-dependencies-{{ checksum "Gemfile.lock" }}

      - restore_cache:
          - v1-yarn-dependencies-{{ checksum "yarn.lock" }}
          - v1-yarn-dependencies-

      - run:
          name: install package.json dependencies
          command: |
            yarn install

      - save_cache:
            - node_modules
          key: v1-yarn-dependencies-{{ checksum "yarn.lock" }}

      # Database setup
      - run: bundle exec rake db:create
      - run: bundle exec rake db:schema:load

      # run tests!
      - run:
          name: run tests
          command: |
            mkdir /tmp/test-results
            TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb")"

            bundle exec rspec --format progress \
                            --out /tmp/test-results/rspec.xml \
                            --format progress \

      # collect reports
      - store_test_results:
          path: /tmp/test-results
      - store_artifacts:
          path: /tmp/test-results
          destination: test-results


When i SSH into this build, the file in question does exist:

circleci@1145de4ad865:~/parting-pro/vendor/bundle/ruby/2.4.0/gems/mysql2-0.4.8/lib/mysql2$ ls -al
total 500
drwxr-xr-x 2 circleci circleci   4096 May 14 03:42 .
drwxr-xr-x 3 circleci circleci   4096 May 14 03:41 ..
-rw-r--r-- 1 circleci circleci   5934 May 14 03:41 client.rb
-rw-r--r-- 1 circleci circleci    121 May 14 03:41 console.rb
-rw-r--r-- 1 circleci circleci   1132 May 14 03:41 em.rb
-rw-r--r-- 1 circleci circleci   2346 May 14 03:41 error.rb
-rw-r--r-- 1 circleci circleci     53 May 14 03:41 field.rb
-rwxr-xr-x 1 circleci circleci 465696 May 14 03:42


I have exactly the same problem.

version: 2
      - image: circleci/ruby:2.4-node
          PGUSER: dfgdfgdfg
          MYSQL_URL: mysql2://root@
          RAILS_ENV: test
      - image: circleci/postgres:9.5-alpine
          POSTGRES_USER: dfgdfgdfg
          POSTGRES_DB: tmr
      - image:
          ELASTIC_PASSWORD: 'dfgdfgdfgdfg'
      - image: circleci/mysql:latest
      - image: redis:latest


Prior to the Rake command, could you list the directory involved to see what is in it? You’d just need a step of:

ls -l /home/circleci/parting-pro/vendor/bundle/ruby/2.4.0/gems/mysql2-0.4.8/lib/mysql2/

If that fails too (because the directory does not exist) then back up one or more levels, and use -R. Hopefully that will help find out what state this folder is in prior to the Rake command needing it.


I have exactly the same problem.
The cause of the details has not been investigated, but it was solved by the following method.
(reinstal mysql2 gem)

      - restore_cache:
            - v2-dependencies-{{ checksum "Gemfile.lock" }}
            - v2-dependencies-

      - run:
          name: install dependencies
          command: |
            bundle install --jobs=3 --retry=3 --path vendor/bundle
      # adding the 2 steps below 
      - run:
          name: remove mysql2 temporary
          command: |
            bundle exec gem uninstall mysql2

      - run:
          name: reinstall mysql2 temporary
          command: |
            bundle install --jobs=3 --retry=3 --path vendor/bundle

      - save_cache:
          key: v2-dependencies-{{ checksum "Gemfile.lock" }}
            - vendor/bundle


Still no solution, but here are some additional details I discovered. Will try the temporary uninstall/reinstall as a workaround.

On a fresh build + SSH into box, here is the PATH and ldd lookup of Note that is part of the shared library lookup. This is an example of the initial build that succeeds.

$PATH is /usr/local/bundle/bin:/usr/local/bundle/gems/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

cd /home/circleci/parting-pro/vendor/bundle/ruby/2.4.0/gems/mysql2-0.4.8/lib/mysql2/
ldd (0x00007ffc6bfd4000) => /usr/local/lib/ (0x00007fd77df91000) => /usr/lib/x86_64-linux-gnu/ (0x00007fd77d98f000) => /lib/x86_64-linux-gnu/ (0x00007fd77d772000) => /lib/x86_64-linux-gnu/ (0x00007fd77d558000) => /lib/x86_64-linux-gnu/ (0x00007fd77d254000) => /lib/x86_64-linux-gnu/ (0x00007fd77d050000) => /lib/x86_64-linux-gnu/ (0x00007fd77ce18000) => /lib/x86_64-linux-gnu/ (0x00007fd77ca79000)
	/lib64/ (0x00007fd77e6ac000) => /usr/lib/x86_64-linux-gnu/ (0x00007fd77c6f7000) => /lib/x86_64-linux-gnu/ (0x00007fd77c4e0000)

On a rebuild these are the results instead:

ldd (0x00007ffc5e16e000) => /usr/local/lib/ (0x00007fe2febe1000) => not found => /lib/x86_64-linux-gnu/ (0x00007fe2fe9c4000) => /lib/x86_64-linux-gnu/ (0x00007fe2fe7aa000) => /lib/x86_64-linux-gnu/ (0x00007fe2fe4a6000) => /lib/x86_64-linux-gnu/ (0x00007fe2fe2a2000) => /lib/x86_64-linux-gnu/ (0x00007fe2fe06a000) => /lib/x86_64-linux-gnu/ (0x00007fe2fdccb000)
	/lib64/ (0x00007fe2ff2fc000)

Note that cannot be found, which I believe is the source of the failure. Unfortunately I have not been able to debug any further. Any help is appreciated.


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