Alexandr
Alexandr

Reputation: 9525

Docker MySql automate configuration of `mysql.user` table (or Ansible)

MySql is installed via docker and ansible scripts.

To be able to login to the container from the host, now I manually login to the container and run the sql statement:

$ docker exec -it bm_my_sql bash
bash-4.2# mysql -uroot -p
update mysql.user set host = '%' where user = 'root';

Then from the host I can login to the container as:

$ mysql -h localhost -P 3306 --protocol=tcp -u root -p

The question is, how can I update mysql.user.host field for the root user via docker configuration or via ansible script.

Cannot find any config settings for this.

Upvotes: 0

Views: 233

Answers (1)

pacuna
pacuna

Reputation: 2089

If you are using the MySQL dockerhub image:

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.

So you can just put a SQL script with that statement in a volume that maps to the /docker-entrypoint-initdb.d dir.

Upvotes: 1

Related Questions