Recently I returned to a Ruby on Rails project I hadn't worked in for a while, and found that every time I ran the migrations, I would get a bunch of unrelated changes in the schema.rb file for tables that weren't changed by the migrations I just ran. The changes were usually on the line defining the table, and contained different values for text encoding related keywords like char set and collate.

To fix this, I ended up needing to update the database-level collation and charset - the mysql server-level settings were correct, but not the settings at the database level.

Here's what I did. In this case mysql was running in Docker, so I'm including the commands for getting in to the mysql instance in the Docker container as a reference for my future self if I ever need to do this again.

# get into the docker container running mysql
$ docker exec -it my-mysql bash -l

# open a mysql console inside that server
$ mysql -h localhost -p --database my_database_name

# don't know your db name? do this:
$ mysql -h localhost -p
# in the sql console now
SHOW DATABASES;

In the SQL console for the specific database you are looking at,

-- check the variable settings
SHOW VARIABLES LIKE '%character_set%';
SHOW VARIABLES LIKE '%collate%';

-- if your database setting needs to change, do this:
ALTER DATABASE my_db_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;

Using the character set and collate values you are wanting to change to, of course.