MySql Server shut down immediately after docker-compose up - mysql

This is my docker-compose file. When I execute sudo docker-compose up I got an error on mysql server.
version: '3'
services:
app:
build:
context: ./
dockerfile: Dockerfile
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '8080:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- redis
- mailhog
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'sail-redis:/data'
networks:
- sail
healthcheck:
test: ["CMD", "redis-cli", "ping"]
retries: 3
timeout: 5s
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sail-mysql:
driver: local
sail-redis:
driver: local
This is what I am getting in terminal:
ech-hub-api-mysql-1 | 2023-01-26T06:43:34.458966Z 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.
tech-hub-api-mysql-1 | 2023-01-26T06:43:34.460098Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 1
tech-hub-api-mysql-1 | 2023-01-26T06:43:34.465939Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
tech-hub-api-mysql-1 | 2023-01-26T06:43:34.562068Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
tech-hub-api-mysql-1 | 2023-01-26T06:43:34.743847Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
tech-hub-api-mysql-1 | 2023-01-26T06:43:34.743907Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
tech-hub-api-mysql-1 | 2023-01-26T06:43:34.744467Z 0 [ERROR] [MY-010259] [Server] Another process with pid 62 is using unix socket file.
tech-hub-api-mysql-1 | 2023-01-26T06:43:34.744489Z 0 [ERROR] [MY-010268] [Server] Unable to setup unix socket lock file.
tech-hub-api-mysql-1 | 2023-01-26T06:43:34.744503Z 0 [ERROR] [MY-010119] [Server] Aborting
tech-hub-api-mysql-1 | 2023-01-26T06:43:36.299171Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.
tech-hub-api-mysql-1 exited with code 1
any advice?
Thanks.
I tried re-configuring mysql and docker. On other machines the file works itself. Then I tried re-installing mysql. Did not work.

I had the same issue when I created a new project with laravel-build. I solved this by simply renaming all related volume names since I have more than one Laravel Sail project.
So, instead of the default one for MySQL
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test:
- CMD
- mysqladmin
- ping
- '-p${DB_PASSWORD}'
retries: 3
timeout: 5s
I used this one (check volumes section)
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'project-name-mysql:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- project-name
healthcheck:
test:
- CMD
- mysqladmin
- ping
- '-p${DB_PASSWORD}'
retries: 3
timeout: 5s
Hope it will help someone
UPD:
Actually, the thing which helped me is just deleting the volume, I realized it later when I found out that my previous volume was still in the list (sail-mysql).

Related

lower_case_table_names error for Docker + MySQL 8.0.26 based project on Ubuntu 20.04 Server(AWS EC2)

I am trying to configure my Django + MySQL(8.0.26) project on Ubuntu 20.04 based AWS EC2 server with Docker Compose. However, MySQL database container is not working because of lower_case_table_names. These are a few solutions solution1, solution2, solution3 which I've already tried but have not been able to find the solution.
I have created a sample project based on this YouTube tutorial which is successfully running on my local machine(macOS 11.4).
docker-compose.yml
version: '3.8'
services:
db:
image: mysql:8.0.26
restart: always
command: --lower_case_table_names=1
environment:
- MYSQL_DATABASE=tutorialdb
- MYSQL_USER=chitrang
- MYSQL_PASSWORD=test123
- MYSQL_ROOT_PASSWORD=test123
ports:
- "3307:3306"
volumes:
- ./dbdata:/var/lib/mysql
backend:
build: .
command: python manage.py runserver 0.0.0.0:8000
ports:
- 8000:8000
volumes:
- .:/app
depends_on:
- db
Error Log:
db_1 | 2021-08-20 01:01:48+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started.
db_1 | 2021-08-20 01:01:50+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1 | 2021-08-20 01:01:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started.
db_1 | 2021-08-20T01:01:51.247142Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.26) starting as process 1
db_1 | 2021-08-20T01:01:52.809303Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
db_1 | 2021-08-20T01:01:56.262851Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
db_1 | 2021-08-20T01:01:56.320513Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('2').
db_1 | 2021-08-20T01:01:56.321126Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
db_1 | 2021-08-20T01:01:56.321630Z 0 [ERROR] [MY-010119] [Server] Aborting
db_1 | 2021-08-20T01:01:56.867684Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.26) MySQL Community Server - GPL.
I have tried to set all the three possible values 0|1|2 for lower_case_table_names in a docker-compose.yml file but error message is similar each time.
I guess solution could be simple but since this my first Backend + DevOps project I might not able to figure it out easily. Moreover, it seems this issue is common and has been faced by many developers so in my opinion either MySQL or Ubuntu team should have resolved it.
Try this, It worked for me:
https://gist.github.com/feltnerm/bb6e23f531803896ca1e
version: '3.8'
services:
db:
image: mysql:8.0.26
restart: always
command: --lower_case_table_names=0
environment:
- MYSQL_DATABASE=tutorialdb
- MYSQL_USER=chitrang
- MYSQL_PASSWORD=test123
- MYSQL_ROOT_PASSWORD=test123
ports:
- "3307:3306"
volumes:
- ./data/initdb.d:/docker-entrypoint-initdb.d
- ./data/mysql:/var/lib/mysql
backend:
build: .
command: python manage.py runserver 0.0.0.0:8000
ports:
- 8000:8000
volumes:
- .:/app
depends_on:
- db

SQLSTATE[HY000] [2002] Connection refused and SQLSTATE[HY000] [2002] Host is unreachable

I maked docker-compose for elasticsearch and mysql. All container installed "safelly" but when i try to log in to my db with adminer and try it many times i can't and some error occured: SQLSTATE[HY000] [2002] Connection refused. I don't know why, i tried to restart my docker and i got SQLSTATE[HY000] [2002] Host is unreachable my db_container keep restarting. Before my db_container keep restarting I already tried to make db manually with docker exec -it db_container_name bash but same still error, i mean can't connect.
Problems:
MySQL container keep restarting and i can't connect to it by adminer
my .env:
DB_MASTER_HOST= $DB_MASTER_HOST
DB_CONNECTION=mysql
DB_MASTER_USERNAME= mysql
DB_MASTER_PASSWORD= mysql
DB_MASTER_NAME= horde
DB_MASTER_PORT= 3306
my docker-composer.yml:
version: "3.7"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
environment:
- node.name=elastic
- cluster.name=es-docker-cluster
- cluster.initial_master_nodes=elasticsearch
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
cap_add:
- IPC_LOCK
volumes:
- /mnt/y/new/app/docker/elasticsearch/data
ports:
- 9200:9200
adminer:
image: adminer
restart: always
ports:
- 9000:8080
environment:
- ADMINER_DESIGN='nette'
mysql_db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: "on-failure"
environment:
MYSQL_DATABASE: "horde"
MYSQL_USER: "mysql"
MYSQL_PASSWORD: "mysql"
MYSQL_ROOT_PASSWORD: "mysql"
volumes:
- /mnt/y/new/app/docker/database/data:/var/lib/mysql
- /mnt/y/new/app/docker/database/conf.d:/etc/mysql/conf.d
ports:
- 3306:3306
mysql_slave:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: "on-failure"
environment:
MYSQL_DATABASE: "horde"
MYSQL_USER: "mysql"
MYSQL_PASSWORD: "mysql"
MYSQL_ROOT_PASSWORD: "mysql"
ports:
- 3307:3306
logs:
2021-04-16 06:53:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-04-16 06:53:07+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-04-16 06:53:07+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-04-16 06:53:08+00:00 [Note] [Entrypoint]: Initializing database files
2021-04-16T06:53:08.860057Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.23) initializing of server in progress as process 42
2021-04-16T06:53:08.954226Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2021-04-16T06:53:08.954244Z 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.
2021-04-16T06:53:08.955403Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-04-16T06:53:08.962536Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.23) MySQL Community Server - GPL.

Docker MySQL container not binding to local port correctly

I'm trying to connect my local 3306 to my docker containers 3306 using docker-compose. This was all working correctly until I encountered an error with MySQL when I tried changing a table name using workbench. Since then I've been unable to connect back to the container with the correct data.
Here is my docker-compose.yml:
version: "3.3"
services:
web_old:
build:
context: ./
dockerfile: ./html/Dockerfile
container_name: mackglobal_old
depends_on:
- db
volumes:
- ./:/var/www
# - ./config/000-default.conf:/etc/apache2/000-default.conf
ports:
- 8000:80
db:
container_name: mysql8_old
image: mysql:8.0.23
environment:
MYSQL_USER: "admin" # same as production so when we create views it doesnt cause definer errors
MYSQL_PASSWORD: "root"
MYSQL_ROOT_PASSWORD: "root"
volumes:
- ./mysql:/var/lib/mysql
- ./my.cnf:/etc/mysql/conf.d/my.cnf
ports:
- "3306:3306"
# command: mysqld --innodb_force_recovery=6 # USE THIS LINE IF THE MYSQL CONTAINER CRASHES TO RECOVER DATA IN READ
When connecting to the database in my application I am met with this PHP PDO error:
Connection failed: SQLSTATE[HY000] [1045] Access denied for user 'admin'#'172.18.0.3' (using password: YES)
When I connect to the mysql instance inside the docker container I am able to access the server using the username and password in the docker-compose file and all of my databases and tables are inside the instance. But when connecting to the instance inside workbench every query I make is met with:
Error Code: 1046. No database selected Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar.
and when running SHOW databases; I only get information_schema
Here are the details I've been using to connect to the instance:
Hostname: MacBook-Pro-2.local (also tried: localhost, 127.0.0.1)
Port: 3306 (I've also changed the port to 3307 in the compose file and get the same errors)
Username: admin
Password: root
Here is my.cnf:
[mysqld]
default_time_zone='+00:00'
sql_mode=""
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init-connect='SET NAMES UTF8;'
innodb-flush-log-at-trx-commit=0
lower_case_table_names=2
and here is the log when running docker-compose up --build:
mysql8_old | 2021-02-16 20:15:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
mysql8_old | 2021-02-16 20:15:38+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql8_old | 2021-02-16 20:15:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
mysql8_old | 2021-02-16T20:15:39.468943Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.23) starting as process 1
mysql8_old | 2021-02-16T20:15:39.506466Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql8_old | 2021-02-16T20:15:40.895843Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql8_old | 2021-02-16T20:15:41.681805Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
mysql8_old | 2021-02-16T20:15:41.848877Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql8_old | 2021-02-16T20:15:41.849540Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql8_old | 2021-02-16T20:15:41.867833Z 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.
mysql8_old | 2021-02-16T20:15:42.028150Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.23' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
I should also note that the last environment I used was mysql:8.0.21 but I arrived at the same errors
Any help is greatly appreciated
Addition:
I've also tried restarting docker service and my laptop as well
When running network utility on port 3306 while containers are active:
Port scanner
EDIT:
Turns out my folder which holds the mysql data ./mysql in my docker compose file is now corrupt (without error) and I'm still unable to access anything in recovery mode. Luckily I had a backup but I lost all my recent changes that I made. I still am unsure what went wrong so I'm leaving this unsolved
In my docker-compose.yml, I made my mysql container like this:
mysql8-service:
image: mysql:8
container_name: mysql8-container
ports:
- "4306:3306"
volumes:
- ./mysql:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always # always restart unless stopped manually
environment:
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: secret
MYSQL_PASSWORD: secret
networks:
- nginx-php74-mysql8-node
It make me able to save my database in the folder of my app, and my credentials are good.

Why is doccker using cached mysql data instead of latest mysql dump?

I have a docker image for mysql datbase.
The first time I made this work I backed up my db to a .sql file and then from my docker-compose I
build up the dabase.
Now however I have made some updates, created a new .sql file and again through the docker-compose I thought I would get my new data and new changes.
my docker-comose file:
services:
mysql:
image: mysql:latest
container_name: mysqldb
cap_add:
- SYS_NICE # CAP_SYS_NICE
# container_name: my_very_special_server
ports:
- 3307:3306
environment:
MYSQL_DATABASE: wedding
MYSQL_ROOT_PASSWORD: SomeRootPassword1!
MYSQL_USER: someuser
MYSQL_PASSWORD: Password1!
volumes:
- ./dbScript/Dump20201018.sql:/docker-entrypoint-initdb.d/Dump20201018.sql
- db_data:/var/lib/mysql
restart: always
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: dev_pma
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3307
PMA_ARBITRARY: 1
restart: always
ports:
- 8183:80
server:
container_name: weddingapp_server
build: ./weddingApp-Be
depends_on:
- mysql
environment:
MYSQL_HOST_IP: mysql
ports:
- 4000:4000
links:
- mysql
command: npm run dev
client:
container_name: weddingapp_client
build: ./weddingApp-Fe
ports:
- 3001:3000
environment:
- CHOKIDAR_USEPOLLING=true
tty: true
volumes:
db_data:
After the build was finished and I spinned it up I saw that my new data wasn't showing up, I still had the old data cached somewhere?
I checked the logs for my mysql image and got this:
2020-10-18 20:46:59+00:00 [Note] [Entrypoint]: Entrypoint script for
MySQL Server 8.0.21-1debian10 started. 2020-10-18 20:46:59+00:00
[Note] [Entrypoint]: Switching to dedicated user 'mysql' 2020-10-18
20:46:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server
8.0.21-1debian10 started. 2020-10-18T20:46:59.686360Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as
process 1 2020-10-18T20:46:59.693458Z 1 [System] [MY-013576] [InnoDB]
InnoDB initialization has started. 2020-10-18T20:46:59.987115Z 1
[System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-10-18T20:47:00.115947Z 0 [System] [MY-011323] [Server] X Plugin
ready for connections. Bind-address: '::' port: 33060, socket:
/var/run/mysqld/mysqlx.sock 2020-10-18T20:47:00.196070Z 0 [Warning]
[MY-010068] [Server] CA certificate ca.pem is self signed.
2020-10-18T20:47:00.196193Z 0 [System] [MY-013602] [Server] Channel
mysql_main configured to support TLS. Encrypted connections are now
supported for this channel. 2020-10-18T20:47:00.200913Z 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-10-18T20:47:00.219538Z 0 [System]
[MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version:
'8.0.21' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL
Community Server - GPL.
I am fairly new to docker and honestly I don't know what I am doing wrong. Any ideas?
initdb scripts are only executed when your data directory (/var/lib/mysql) is empty.
Your data are not cached, but persisted to your host using your volume. So if this is a development work, you can simply delete the contents of db_data volume (or deleting and creating it again):
docker volume rm db_data
docker volume create db_data

MySQL container stalls at "X Plugin ready for connections" after docker-compose up

I'm using docker-compose to start up a simple MySQL docker container.
The yml file:
version: '3'
services:
local:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: password
ports:
- "3316:3306"
volumes:
- "./data:/var/lib/mysql:rw"
When I run docker-compose up, the process stalls at:
local_1 | 2020-02-15T21:33:02.320280Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060