Is it possible to set collation and charset to MySQL service in Bitbucket Pipeline?

mullermartin October 4, 2021

I use MySQL database in Bitbucket build pipeline defined like this:

definitions:
services:
mysql:
image: mysql:5.7
variables:
MYSQL_DATABASE: testbase
MYSQL_ROOT_PASSWORD: pass

But it use wrong (default) charset and collation. I need UTF-8 to get rid of exceptions like:

SQLException: Incorrect string value: '\xC5\x88' for column 'city' at row 1

Is there a way to fix it in bitbucket-pipelines.yml? In a standard Docker setup I can fix it this way:

database:
image: mysql:5.7
environment:
MYSQL_DATABASE: testbase
MYSQL_ROOT_PASSWORD: pass
command: [ 'mysqld', '--character-set-server=utf8', '--collation-server=utf8_general_ci' ]

 

2 answers

2 accepted

1 vote
Answer accepted
mullermartin October 8, 2021

In the end, I have used another solution. It seems not possible to create MySQL service in Bitbucket using proper charset & collation. But it is possible to use SQL script to fix it just on database schema level:

alter database my_database_name
character set utf8
collate utf8_general_ci;

I use the database just for my automated integration tests. So I have set Liquibase to start DB initialization with setting proper charset & collation.

In case you prefer to do it on table level because you are no allowed to alter whole database schema you can use:

create table my_table (...
) character set utf8 collate utf8_general_ci;
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 12, 2021

Thank you Martin for posting the solution that you used.

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 6, 2021

Hi @mullermartin,

At the moment I'm afraid that it is not possible to pass a command to a Docker service container, like in the example you included.

We have a feature request about this in our issue tracker:

If you'd be interested in this, I would suggest that you add your vote in that request (by selecting the Vote for this issue link) as the number of votes helps the development team and product managers better understand the demand for new features. You are more than welcome to leave any feedback, and you can also add yourself as a watcher (by selecting the Start watching this issue link) if you'd like to get notified via email on updates.

In the meantime, a way to work around this issue would be to create a custom Docker image (based on the official mysql image) that sets your own CMD value, or supports environment variables for settings like these.

Kind regards,
Theodora

mullermartin October 6, 2021

Thank you for the link and the solution proposal. I have upvoted the issue.

 

Regards,

Martin

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events