Can't run a MySQL slave instance on GKE - mysql

I have a MySQL service running on Google Kubernetes Engine configured with Master-Slave replication strategy. Unfortunately up until now only I am only managed to have the master (mysql-0) instance running. Slave instances (mysql-n) always stuck on CrashLoopBackOff.
Current pods:
When I check the log for mysql-1 instance, the following lines printed:
2020-01-08 08:11:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
2020-01-08 08:11:20+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-01-08 08:11:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
2020-01-08 08:11:20+00:00 [Note] [Entrypoint]: Initializing database files
2020-01-08T08:11:20.787668Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-01-08T08:11:20.787780Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.18) initializing of server in progress as process 45
2020-01-08T08:11:20.789731Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2020-01-08T08:11:20.789739Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2020-01-08T08:11:20.790259Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-01-08T08:11:20.791368Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.18) MySQL Community Server - GPL.
On the master MySQL Instance (mysql-0), the following lines printed:
2020-01-08 08:08:02+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
2020-01-08 08:08:03+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-01-08 08:08:03+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
2020-01-08T08:08:03.605134Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-01-08T08:08:03.605280Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 1
2020-01-08T08:08:05.939722Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-01-08T08:08:05.945787Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-01-08T08:08:06.069048Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.18' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2020-01-08T08:08:06.303012Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
The key difference between the two logs is, on the slave instance, the line Initializing database files are printed, indicating mysqld attempted to initalize already existing mysql data directory (/var/lib/mysql) whereas it doesn't happen when the master instance initializes.
I was following this kubernetes guide but it doesn't work on MySQL version 8. So I modify the StatefulSet deployment. Here is the yaml snippet
Anybody has idea on how to solve this problem? Much appreciated :)
UPDATE:
Solution provided by #BinaryBullet actually works with some changes down the line to enable multiple slaves replication. This yaml file is the end result.

I could see this is the issue with your volumemount, as you have single VolumeClaimTemplate for both master and slave mysql-bin files, schemas, ib_buffer_pool, etc all other mysql related files are conflicting with each other and trying to save at the same location. Due to this one of your db instance is failing, i.e. which ever starting later is failing, in your case slave db.
This could be avoided by adding separate PV and PVC for your master and slave.
Addition of something like this to your statefulset
volumeClaimTemplates:
- metadata:
name: slave-data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
And volumemount for slave pod is something like this
volumeMounts:
- name: slave-data
mountPath: /var/lib/mysql
subPath: mysql
- name: conf
mountPath: /etc/mysql/conf.d
But make sure you have a separate Persistent Volume for your slave as well. To which all your slave mysql-bin files, ib_buffer_pool, schemas, etc mysql related files get saved in a different location from master.
Hope this helps.

Related

The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it inside the Kubernetes Pod

I am running Minikube version 1.20 w/ KVM2 as a VM driver inside my Ubuntu 20.04 LTS. When I am trying to deploy SQL inside my local Kubernetes cluster. It keeps restarting with the below pod logs error
2023-01-17 07:15:17+00:00 [Note] [Entrypoint]: Initializing database files
2023-01-17T07:15:17.153897Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2023-01-17T07:15:17.154020Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2023-01-17T07:15:17.154036Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31) initializing of server in progress as process 42
2023-01-17T07:15:17.155532Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2023-01-17T07:15:17.155536Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2023-01-17T07:15:17.155571Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-01-17T07:15:17.155647Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL.
I am trying to use mysql:8 image and mountPath: /var/lib/mysql.
Seems like the volume contains something from the error. You can try to delete the pod and related resources (e.g. PVC, service, etc), delete the data directory and any files within it. After, create the pod again and make sure that the data directory is empty and not being used by any other pod or service and make sure that the mountPath: /var/lib/mysql should be empty before the pod creation.
If you tried multiple times i would suggest trying deleting everything first and applying changes again PV and PVC. There could be changes in PVC, PVC old files exist which causes issues.
Try deploying everything again and also check MySQL image.
You can refer this for more info : https://stackoverflow.com/a/70800469/5525824

MySQL docker container receives SHUTDOWN command

everyone. I have noticed strange behavior during MySQL docker container startup. Basically I'm trying to run the following command
docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.29
but after that I see from the logs that container after successful startup suddenly receives SHUTDOWN command, and reinitialize database again
2022-07-25T19:33:26.423537Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29) MySQL Community Server - GPL.
Here is all the logs:
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Initializing database files
2022-07-25T19:33:19.770157Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.29) initializing of server in progress as process 42
2022-07-25T19:33:19.775554Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-25T19:33:20.037982Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-25T19:33:21.277581Z 6 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2022-07-25 19:33:23+00:00 [Note] [Entrypoint]: Database files initialized
2022-07-25 19:33:23+00:00 [Note] [Entrypoint]: Starting temporary server
2022-07-25T19:33:23.494658Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 91
2022-07-25T19:33:23.505604Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-25T19:33:23.590481Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-25T19:33:23.778598Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-07-25T19:33:23.778621Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-07-25T19:33:23.779801Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2022-07-25T19:33:23.790924Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
2022-07-25T19:33:23.790961Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.29' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2022-07-25 19:33:23+00:00 [Note] [Entrypoint]: Temporary server started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2022-07-25 19:33:24+00:00 [Note] [Entrypoint]: Stopping temporary server
2022-07-25T19:33:24.911894Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.29).
2022-07-25T19:33:26.423537Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29) MySQL Community Server - GPL.
2022-07-25 19:33:26+00:00 [Note] [Entrypoint]: Temporary server stopped
2022-07-25 19:33:26+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2022-07-25T19:33:27.122487Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1
2022-07-25T19:33:27.128121Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-25T19:33:27.217345Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-25T19:33:27.410605Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-07-25T19:33:27.410659Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-07-25T19:33:27.412287Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2022-07-25T19:33:27.431360Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-07-25T19:33:27.431373Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.29' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
And after second attempt container is up and running normally. So my question is - how to identify what causes to the SHUTDOWN command?
That's a normal consequence of the way the mysql image runs its first-time initialization scripts. Note the Initializing database files message and the Temporary server started...Temporary server stopped around the first Received SHUTDOWN message.
You can see this logic in the entrypoint script itself. That script runs (using shell functions defined previously in the script, trimmed down somewhat)
# there's no database, so it needs to be initialized
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_init_database_dir "$#"
mysql_note "Starting temporary server"
docker_temp_server_start "$#"
mysql_note "Temporary server started"
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*
mysql_note "Stopping temporary server"
docker_temp_server_stop
mysql_note "Temporary server stopped"
fi
The mysql_note lines are visible in the container output you quote.
More specifically, the temporary server is accessible over a Unix socket within the container filesystem, but it is not accessible over the network. This gives a point where the database hasn't been set up yet, but it's still possible to run local mysql commands, for example from the initdb scripts. Once this phase has been complete, then the database restarts with its normal options.
If you're probing to see if the database is ready yet, maybe using a mysql client in a shell loop or a TCP client like the wait-for script, this means that the database won't appear "ready" until all of the initdb scripts have run.

Install multiple MySQL clusters on same machine - CentOS 7

I am new to MySQL and i'm trying to create multiple mysql clusters on the same host with different port number. I know that default port is 3306 so I tried to configure the my.cnf to something like this:
[mysqld2]
datadir=/var/lib/mysql2
port=3307
and then run mysql -P 3307 but that doesn't work. I don't know how to start the cluster on this port.
Please send help :)
Edit:
So i found out I need to create another configuration file and made it to here:
mkdir -p /var/lib/mysql2
chmod --reference /var/lib/mysql /var/lib/mysql2
chown --reference /var/lib/mysql /var/lib/mysql2
cp -p /etc/my.cnf /etc/my2.cnf
vi /etc/my2.cnf
--------------------------------------
[mysqld]
datadir=/var/lib/mysql2
socket=/var/lib/mysql/mysql2.sock
port=3337
[mysqld_safe]
log-error=/var/log/mysqld2.log
pid-file=/var/run/mysqld/mysqld2.pid
--------------------------------------
mysqld --initialize-insecure --user=mysql --datadir=/var/lib/mysql2
Now I have a new data directory set and a configuration file, problem is I don't know how to start this specific cluster(with this configuration file I made)
Edit2:
Now when I run mysqld --defaults-file=/etc/my2.cnf i get this error:
[root#pg66 ~]# mysqld --defaults-file=/etc/my2.cnf
2020-12-31T09:50:08.821792Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22) starting as process 28085
2020-12-31T09:50:08.838198Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-12-31T09:50:09.551655Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-12-31T09:50:10.670160Z 0 [ERROR] [MY-011292] [Server] Plugin mysqlx reported: 'Preparation of I/O interfaces failed, X Protocol won't be accessible'
2020-12-31T09:50:10.670328Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of bind-address: '*' port: 33060 failed, `bind()` failed with error: Address already in use (98). Do you already have another mysqld server running with Mysqlx ?'
2020-12-31T09:50:10.670440Z 0 [ERROR] [MY-013597] [Server] Plugin mysqlx reported: 'Value '*' set to `Mysqlx_bind_address`, X Plugin can't bind to it. Skipping this value.'
2020-12-31T09:50:10.670592Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of socket: '/var/run/mysqld/mysqlx.sock' failed, another process with PID 26783 is using UNIX socket file'
2020-12-31T09:50:11.007743Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-12-31T09:50:11.007904Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2020-12-31T09:50:11.063486Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.22' socket: '/var/lib/mysql/mysql2.sock' port: 3337 MySQL Community Server - GPL.
^C^C^[[A^C
you need to launch mysql with your config file.
mysqld_safe – -defaults-file=/etc/my2.cnf && mysqld_safe – -defaults-file=/etc/my1.cnf
More infos: https://dev.mysql.com/doc/refman/8.0/en/multiple-servers.html

I am getting wordpress mysql connection error using docker

I created two docker containers using the commands below.
docker pull wordpress
docker pull mysql
docker run --name wordpress_database -e MYSQL_ROOT_PASSWORD=password -d mysql
docker run --name wordpress_website --link wordpress_database:mysql -p 8080:80 -d wordpress
When I looked at the later logs, I encountered an error. Logs are below.
How do I prevent these errors?
docker logs wordpress_website
WordPress not found in /var/www/html - copying now...
Complete! WordPress has been successfully copied to /var/www/html
[15-Apr-2020 12:08:38 UTC] PHP Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in Standard input code on line 22
[15-Apr-2020 12:08:38 UTC] PHP Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in Standard input code on line 22
MySQL Connection Error: (2054) The server requested authentication method unknown to the client
[15-Apr-2020 12:08:41 UTC] PHP Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in Standard input code on line 22
[15-Apr-2020 12:08:41 UTC] PHP Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in Standard input code on line 22
WARNING: unable to establish a database connection to 'mysql'
continuing anyways (which might have unexpected results)
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
[Wed Apr 15 12:09:06.057462 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.16 configured -- resuming normal operations
[Wed Apr 15 12:09:06.057505 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
docker logs wordpress_database
2020-04-15 12:07:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Initializing database files
2020-04-15T12:07:20.102858Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-04-15T12:07:20.102959Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 43
2020-04-15T12:07:23.537919Z 5 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-04-15 12:07:27+00:00 [Note] [Entrypoint]: Database files initialized
2020-04-15 12:07:27+00:00 [Note] [Entrypoint]: Starting temporary server
2020-04-15T12:07:27.774674Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-04-15T12:07:27.774765Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 93
2020-04-15T12:07:28.389657Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-04-15T12:07:28.397651Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-04-15T12:07:28.421413Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2020-04-15 12:07:28+00:00 [Note] [Entrypoint]: Temporary server started.
2020-04-15T12:07:28.457791Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2020-04-15 12:07:30+00:00 [Note] [Entrypoint]: Stopping temporary server
2020-04-15T12:07:30.812504Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.19).
2020-04-15T12:07:32.529079Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19) MySQL Community Server - GPL.
2020-04-15 12:07:32+00:00 [Note] [Entrypoint]: Temporary server stopped
2020-04-15 12:07:32+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2020-04-15T12:07:33.133835Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-04-15T12:07:33.133938Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 1
2020-04-15T12:07:33.647310Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-04-15T12:07:33.652627Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-04-15T12:07:33.673452Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2020-04-15T12:07:33.812073Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
localhost:8080
Error establishing a database connection
You need to publish ports to the host interface for MySQL container. Use this command to start the MySQL docker container:
docker run --name wordpress_database -e MYSQL_ROOT_PASSWORD=password -d -p 3306:3306 mysql
Read this for more details regarding publishing ports in a docker container.

MySQL Docker Image: initialized with env variable of K8S Secret

When i tried to deploy with K8S using env variable for Root Password (MYSQL_ROOT_PASSWORD , a variable used in docker-entrypoint.sh) such as
kind: Deployment
#omitted...
spec:
containers:
#omitted...
env:
- name: MYSQL_ROOT_PASSWORD
value: my-secret-passw
it seems that the deployment with kubectl apply -k is working. Of course, this insecure deployment. MySql initialization works and everything is as expected.
So i tried to create a secret and retrieving the value from that secret, such that
kind: Deployment
#omitted...
spec:
containers:
#omitted...
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
key: MYSQL_ROOT_PASSWORD
name: mysql-root-password
mysql initialization is not working. And i have no idea what the heck is going wrong. The kubectl logs or stdout from the container is the following (bear in mind that using literal root pass didn't return result like this):
[MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
[Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/sql-script.sql
mysql: [ERROR] unknown option '-- "'.
When checking the docker image source code, it seems there is no string about "unknown option" (see here the github and i am using mysql 8.0. It seems it's coming out of mysql itself.
So why is it that when using literal value on k8S env variable (which is not safe!) working but not with reading from secret?
Seems like version 8.0 is broken or missing something because it cannot see the password.
I'm not an expert in this field so maybe someone else can add some more details.
2020-02-07T16:09:06.648827Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-02-07T16:09:06.649084Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 44
2020-02-07T16:09:10.821145Z 5 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-02-07 16:09:14+00:00 [Note] [Entrypoint]: Database files initialized
2020-02-07 16:09:14+00:00 [Note] [Entrypoint]: Starting temporary server
2020-02-07T16:09:14.823453Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-02-07T16:09:14.823582Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 94
2020-02-07T16:09:15.631008Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-02-07T16:09:15.635649Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-02-07T16:09:15.655790Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2020-02-07 16:09:15+00:00 [Note] [Entrypoint]: Temporary server started.
2020-02-07T16:09:15.740600Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2020-02-07 16:09:19+00:00 [Note] [Entrypoint]: Stopping temporary server
2020-02-07T16:09:19.476870Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.19).
I've tested the image 5.6 from official mysql repository and it's seems to work perfectly fine.
I've run whole MySQL + WordPress deployment using the Tutorial on kubernetes.io which I do recommend.
I've created the secret manually, using:
kubectl create secret generic mysql-pass --from-literal=password=test
Looks like there is an issue open for problem similar to this "Unable to start server" on Amazon Linux AMI (works with 5.7) #628.
After sometime, i realized that the problem is not with the Secret of K8S. I accidentally changed my password into string of chars without Special characters, and that solved it! From the post, you see that the character -- was read as an input of the next process (dang it, i am giving away my pass! nah, changed it already).
So anyone of you with the same problem (with mysql), please consider choosing a secret with no-special-characters password. Long password with combination of numbers/case-sensitive could be strong enough, especially if you paper and pencil!