Configure Gitlab CE (Omnibus package) to work with MySQL

Mostly follow instructions here, thanks for vitalis

This post just created in case that post gone, and some personal note.

First, install gitlab-ce by the official instructions, and create a mysql database and a user with access ready for gitlab.

Here goes the configurations

Switch db adaptor to mysql2, fill up connection info, disable PostgreSQL

/etc/gitlab/gitlab.rb
1
2
3
4
5
6
7
8
9
# configure to use mysql
gitlab_rails['db_adapter'] = "mysql2"
gitlab_rails['db_encoding'] = "utf8" # must be utf8, utf8mb4 will cause index size too large error
gitlab_rails['db_database'] = "gitlabhq_production"
gitlab_rails['db_username'] = "gitlab"
gitlab_rails['db_password'] = "gitlabdb"
gitlab_rails['db_host'] = "127.0.0.1"
gitlab_rails['db_port'] = 3306
postgresql['enable'] = false

Build mysql2 gem

1
2
3
apt install libmysqlclient-dev gcc # need some dependency
cd /opt/gitlab/embedded/bin/ # use the gem binary package builded
./gem install mysql2 -- --with-mysql-lib=/usr/lib64/mysql

Tell GitLab bundle to ignore PostgreSQL instead of MySQL
(will be revert if gitlab-ce updated, need to manuallly redo when update)

/opt/gitlab/embedded/service/gitlab-rails/.bundle/config
1
2
3
4
5
6
---
BUNDLE_RETRY: "5"
BUNDLE_PATH: "/opt/gitlab/embedded/service/gem"
BUNDLE_JOBS: "9"
BUNDLE_WITHOUT: "development:test:postgres"
BUNDLE_DISABLE_SHARED_GEMS: "true"

Install bundle

1
2
cd /opt/gitlab/embedded/service/gitlab-rails
/opt/gitlab/embedded/bin/bundle install

Reconfigure & restart gitlab

1
2
3
gitlab-ctl reconfigure
gitlab-ctl restart
gitlab-rake gitlab:setup