3

I'm unable to start mysql demon when executing mysqld in a bash script at the end of my Dockerfile width CMD [ "./myscript.sh" ]. However, CMD [ "mysqld" ] works.

Dockerfile

FROM mysql:5.7
USER mysql
COPY ./setconf.sh .
COPY config/my.cnf /etc/mysql/conf.d
CMD [ "./setconf.sh" ]

# CMD ["mysqld"]
# This command works ! 

I'm getting this error:

[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to         create it
[ERROR] Fatal error: Can't open and lock privilege tables: Table     'mysql.user' doesn't exist

docker-compose.yml

  mysql:
    build: mysql
    environment:
      MYSQL_PASSWORD: pass
      MYSQL_ROOT_PASSWORD: pass
      HOST: mysql
      MYSQL_ROOT_HOST: mysql
    ports:
         - "3306:3306"

./setconf.sh

mysqld

Note:

  • I'm doing docker-compose down at every try
  • I need special options to run mysql

my.cnf

[mysqld]
default-storage-engine = INNODB
sql-mode = "STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
transaction-isolation = READ-COMMITTED
innodb_flush_log_at_trx_commit = 1
init_connect = "set session autocommit=0"
log_bin_trust_function_creators = 1
max_sp_recursion_depth = 100
lower_case_table_names = 1
thread_stack = 256K
max_allowed_packet = 16M

Check the Detailled docker-compose logs

2 Answers 2

3

I do not know a good solution but here is a workaround you could use: get rid of you CMD and use

CMD ["mysqld"]

instead. Then copy your script into /docker-entrypoint-initdb.d/ :

COPY /configureDB.sh /docker-entrypoint-initdb.d/

Your script will be executed as soon as mysql is started. for more info, see the mysql docker documentation : https://github.com/docker-library/docs/tree/master/mysql#initializing-a-fresh-instance

Initializing a fresh instance: When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.

Yet, this is not the response you're lokking for, I don't know why you cant start mysqld from a script.

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

Comments

1

Most probably it is happening because you are not initializing your database. You need to run

mysqld --initialize

or

mysqld --initialize-insecure ( for empty root password )

if you are running mysql for the first time.

The docker-entrypoint.sh file in mysql official docker image handles all this for you.

Comments

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.