<commit_before>---
title: MySQL
layout: page
tags:
  - services
  - databases
  - mysql
categories:
  - databases
---
MySQL **5.6** runs on the default port and the credentials are stored in the `MYSQL_USER` and `MYSQL_PASSWORD` environment variables.

The default databases created for you are **development** and **test**.

## 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:

```yaml
development:
  adapter: mysql2
  host: localhost
  encoding: utf8
  pool: 10
  username: <%= ENV['MYSQL_USER'] %>
  password: <%= ENV['<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['<PASSWORD>'] %>
  database: test<%= ENV['TEST_ENV_NUMBER'] %>
  socket: /var/run/mysqld/mysqld.sock
```

Then in your setup commands run

```shell
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:

```shell
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:

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

## Django

```python
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',
  }
}
```<commit_msg>Update ERB to load database.yml<commit_after>---
title: MySQL
layout: page
tags:
  - services
  - databases
  - mysql
categories:
  - databases
---
MySQL **5.6** runs on the default port and the credentials are stored in the `MYSQL_USER` and `MYSQL_PASSWORD` environment variables.

The default databases created for you are **development** and **test**.

## 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:

```yaml
development:
  adapter: mysql2
  host: localhost
  encoding: utf8
  pool: 10
  username: <%= ENV['MYSQL_USER'] %>
  password: <%= ENV['<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['<PASSWORD>'] %>
  database: test<%= ENV['TEST_ENV_NUMBER'] %>
  socket: /var/run/mysqld/mysqld.sock
```

Then in your setup commands run

```shell
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:

```shell
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:

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

## Django

```python
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',
  }
}
```
{'fraction_non_alphanumeric': 0.1383832976445396, 'fraction_numerical': 0.009100642398286937, 'mean_word_length': 4.204735376044568, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4431631', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1241, 'n_words': 406}