Search code examples
mysqldockerdocker-composedockerfile

Docker build: error: ER_NOT_SUPPORTED_AUTH_MODE: MySQL client


When I try docker-compose -f docker-compose-now.yml up I get this message

error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

Now, I did read this solution:

use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';

from: https://github.com/mysqljs/mysql/issues/1507

but how can I put it in my docker-compose-now.yml file in entrypoints?

My environment is in this file, and when I try:

entrypoints: sh "update user set authentication_string=password(''), plugin='mysql_native_password' where user='root'"

I only get another error.

How can I resolve this please?


Solution

  • Problem

    To put things in perspective, what you're doing in your entry point script is actually being executed in the sh shell. The commands you want to run should be executed inside a mysql shell.

    Solution

    Your entrypoint should have the following command instead to run the mysql commands:

    mysql -u root -p [root-password] -e "update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';"
    

    If you wanna do this on mysql db, you can do

    mysql -u root -p [root-password] mysql -e "update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';"
    

    Explanation

    In this command, first you enter in mysql shell using mysql -u -p command and then you execute the sql command using -e flag(it stands for execute). Whatever comes after -e is executed in mysql shell (like queries etc). For details and examples, refer to this:

    https://dev.mysql.com/doc/refman/8.0/en/command-line-options.html