This article is about Codeship Basic.

MySQL

You'll need about one minute to read this article.

MySQL 5.6 runs on the default port and the credentials are stored in the MYSQL_USER and MYSQL_PASSWORD environment variables.

A development and test database are setup by default for you in addition to the system databases.

Ruby on Rails

We replace the values in your config/database.yml automatically.

If you have your Rails application in a subdirectory or want to change it from our default values you can add the following to a codeship.database.yml (or any other filename) in your repository:

development:
  adapter: mysql2
  host: localhost
  encoding: utf8
  pool: 10
  username: <%= ENV['MYSQL_USER'] %>
  password: <%= ENV['MYSQL_PASSWORD'] %>
  database: development<%= ENV['TEST_ENV_NUMBER'] %>
  socket: /var/run/mysqld/mysqld.sock
test:
  adapter: mysql2
  host: localhost
  encoding: utf8
  pool: 10
  username: <%= ENV['MYSQL_USER'] %>
  password: <%= ENV['MYSQL_PASSWORD'] %>
  database: test<%= ENV['TEST_ENV_NUMBER'] %>
  socket: /var/run/mysqld/mysqld.sock

Then in your setup commands run

cp codeship.database.yml YOUR_DATABASE_YAML_PATH

to copy the file wherever you need it.

If you don’t use Rails and load the database.yml yourself you might see an error like the following:

MYSQL2::Error: Access denied for user '<%= ENV['MYSQL_USER'] %>'@'localhost'

The database.yml example has ERB syntax in it so you need to load it by interpreting the ERB first:

DATABASE_CONFIG = YAML.load(ERB.new(File.read("config/database.yml")).result)

Django

DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'test',
    'USER': os.environ.get('MYSQL_USER'),
    'PASSWORD': os.environ.get('MYSQL_PASSWORD'),
    'HOST': '127.0.0.1',
  }
}