I am getting wordpress mysql connection error using docker - mysql

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.

Related

Mysql not starting on docker

I'm using laravel sail to launch a statamic website on my local machine (macOS). All packages are up-to-date and launch correctly however, the mysql service starts, then fails due to "another process with pid 62 is using unix socket file.".
I'm using the default sail docker-compose file, uneditted. It is working on my other, linux machine correctly with no issues. When visiting localhost, I'm met with "SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Name or service not known" which makes me think that it is connecting somehow as I would normally expect connection refused?
Here are the docker mysql container logs:
[Entrypoint] MySQL Docker Image 8.0.32-1.2.11-server
[Entrypoint] Starting MySQL 8.0.32-1.2.11-server
2023-01-26T21:17:04.876429Z 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-26T21:17:04.878708Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 1
2023-01-26T21:17:04.885183Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-01-26T21:17:05.037353Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-01-26T21:17:05.189336Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-01-26T21:17:05.189362Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-01-26T21:17:05.189506Z 0 [ERROR] [MY-010259] [Server] Another process with pid 62 is using unix socket file.
2023-01-26T21:17:05.189518Z 0 [ERROR] [MY-010268] [Server] Unable to setup unix socket lock file.
2023-01-26T21:17:05.189521Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-01-26T21:17:06.724573Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.
Thanks in advance.
I solve mine (WSL2, Docker Desktop) by opening the Docker Desktop GUI, opened the Volumes sidebar. Search for all volume that has "mysql" on their name and delete those volumes. Then run docker compose up again.

Unable to start mysql from official docker image: No space left on device

I just pulled the official mysql image, more precisely: mysql:8.0.32.
Using the following command throws an error:
docker run -e MYSQL_ALLOW_EMPTY_PASSWORD=true -d mysql:8.0.32
2023-01-26T10:46:07.380836Z 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-26T10:46:07.380926Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.32) initializing of server in progress as process 81
mysqld: Error writing file '/var/lib/mysql/auto.cnf' (OS errno 28 - No space left on device)
2023-01-26T10:46:07.386811Z 0 [ERROR] [MY-010076] [Server] Initialization of the server's UUID failed because it could not be read from the auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID.
2023-01-26T10:46:07.386835Z 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-26T10:46:07.386840Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-01-26T10:46:07.387240Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.
2023-01-26 10:46:06+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.32-1.el8 started.
2023-01-26 10:46:07+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2023-01-26 10:46:07+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.32-1.el8 started.
2023-01-26 10:46:07+00:00 [Note] [Entrypoint]: Initializing database files
As you can see, the first error indicates a file could not be written:
mysqld: Error writing file '/var/lib/mysql/auto.cnf' (OS errno 28 - No space left on device)
However, there is nothing mentionning any prerequisite in the documentation.
How am I supposed to solve this problem ?

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

Can't run a MySQL slave instance on GKE

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.