Search code examples
mysql

unknown variable 'default-authentication-plugin=mysql_native_password'


I try to launch mysql container with docker compose and I received error

unknown variable 'default-authentication-plugin=mysql_native_password'.

I have this in my docker-compose.yml

db:
    image: mysql:8.4
    command: ["mysqld", "--default-authentication-plugin=mysql_native_password"]
    restart: unless-stopped
    ports:
        - 3306:3306
    environment:
        MYSQL_RANDOM_ROOT_PASSWORD: yes
        MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password
        MYSQL_DATABASE: ${MYSQL_DATABASE:-learn}
        MYSQL_USER: ${MYSQL_USER:-learn}
        MYSQL_PASSWORD: ${MYSQL_PASSWORD:-test2024}
    volumes:
        - mysql_dev:/var/lib/mysql
        - ./docker/laravel/config/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
    healthcheck:
        test: [ "CMD", 'mysqladmin', 'ping', '-h', 'localhost', '-u', '$$MYSQl_USER', '-p$$MYSQL_PASSWORD' ]
        timeout: 20s
        retries: 2

And in my.cnf file I have this :

[mysqld]
mysql_native_password=ON
default-authentication-plugin=mysql_native_password
general_log = 0
general_log_file = /var/lib/mysql/general.log
default_time_zone='+00:00'

I have tried to change the image version of mysql, but it didn't work. If I downgrade version to 5.7 and change volume name it works, but I want to upgrade the mysql version.


Solution

  • There is no default-authentication-plugin parameter in Mysql 8.4. You can get all mysqld parameters and description for --mysql-native-password as shown below

    mysqld --verbose --help
    ...
      --mysql-native-password[=name] 
                          Enable or disable mysql_native_password plugin. Possible
                          values are ON, OFF, FORCE (don't start if the plugin
                          fails to load).
    ...
    

    So for your docker-compose.yml, change the line from

        command: ["mysqld", "--default-authentication-plugin=mysql_native_password"]
    

    to

        command: ["mysqld", "--mysql-native-password=ON"]
    

    and comment out default-authentication-plugin in my.cnf

    [mysqld]
    mysql_native_password=ON
    #default-authentication-plugin=mysql_native_password
    general_log = 0
    general_log_file = /var/lib/mysql/general.log
    default_time_zone='+00:00'
    

    Then try rebooting the container again; it should work.