2

I'd like to configure the ft_min_word_len and ft_stopword_file settings in my MySQL container. I need shorter words to be indexed as fulltext, and I don't want to use a stopword file at all.

I tried to set the variables with arguments in my docker-compose.yml:

version: "3.4"
services:
  ata-mysql:
    restart: unless-stopped
    image: mysql:5.7.22
    command:
      - "mysqld"
      - "--innodb_buffer_pool_size=400M"
      - "--innodb_buffer_pool_instances=1"
      - "--ft_min_word_len=1"
      - "--ft_stopword_file=''"

But after a restart, it looks like MySQL hasn't picked up this configuration:

mysql> show variables like 'ft_min_word_len';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| ft_min_word_len | 4     |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> show variables like 'ft_stopword_file';
+------------------+------------+
| Variable_name    | Value      |
+------------------+------------+
| ft_stopword_file | (built-in) |
+------------------+------------+
1 row in set (0.01 sec)

Is it possible to set those variables through an argument? I'd like to avoid creating a separate Dockerfile for this kind of configuration.

1
  • 1
    Use a read-only volume to a custom my.cnf in your docker-compose.yml Commented Jan 2, 2021 at 9:54

2 Answers 2

5

It turns out, the command line format for this options uses dashes, and not underscores.

So, the settings must look like this

version: "3.4"
services:
  ata-mysql:
    restart: unless-stopped
    image: mysql:5.7.22
    command:
      - "mysqld"
      - "--innodb_buffer_pool_size=400M"
      - "--ft-min_word-len=1"
      - "--ft-stopword-file=''"

Important: Only after I dropped and re-added the index, the settings took effect.

BTW: For InnoDB these two options are --innodb-ft-min-token-size and --innodb-ft-enable-stopword

Sign up to request clarification or add additional context in comments.

Comments

-1

Well, you're making it harder on yourself by avoiding Dockerfile ENV parameters or my.cnf file methods.

The problem with your setup is that each line within the array will be handled as a separated command like "mysqld" then "--innodb_buffer_pool_size=400M" and so on, which causes the unexpected behavior.

The correct way is to apply the command in your docker-compose.yml as a one line command like this:

version: "3.4"
services:
  data-mysql:
    restart: unless-stopped
    image: mysql:5.7.22
    command:
      - "mysqld --innodb_buffer_pool_size=400M --innodb_buffer_pool_instances=1 --ft_min_word_len=1 --ft_stopword_file=''"

Or you may use the docker compose environment option like this:

version: "3.4"
services:
  data-mysql:
    environment:
      - EXAMPLE=EXAMPLE
      - EXAMPLE=EXAMPLE
      - EXAMPLE=EXAMPLE

And you can get the list of MYSQL ENV from here: https://dev.mysql.com/doc/refman/5.7/en/environment-variables.html

1 Comment

I don't think that's true, you can write a command as an array, see github.com/compose-spec/compose-spec/blob/master/… And because YAML parses multiple lines with a leading - as an array, this works. I can confirm this by looking at the actual command. docker ps --no-trunc shows me the following command: "docker-entrypoint.sh mysqld --innodb_buffer_pool_size=400M --innodb_buffer_pool_instances=1 --ft_min_word_len=1 --ft_stopword_file=''" Unfortantely, the MYSQL ENV Variables don't include settings for the fulltext index.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.