I m trying to dockerize a laravel project a small problem with my MySQL Container.
I cant connect to the container my DB with root or simple user.
I only used docker-compose build && docker-compose up -d
docker exec -it ica-backoffice_attendize_db_1 /bin/bash
mysql -u root -p
Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
This is my docker log : docker logs ica-backoffice_attendize_db_1
2021-03-30 12:20:44+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.33-1debian10 started.
2021-03-30 12:20:44+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-03-30 12:20:44+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.33-1debian10 started.
2021-03-30T12:20:44.525563Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-03-30T12:20:44.527413Z 0 [Note] mysqld (mysqld 5.7.33) starting as process 1 ...
2021-03-30T12:20:44.532377Z 0 [Note] InnoDB: PUNCH HOLE support available
2021-03-30T12:20:44.532396Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-03-30T12:20:44.532402Z 0 [Note] InnoDB: Uses event mutexes
2021-03-30T12:20:44.532407Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-03-30T12:20:44.532425Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-03-30T12:20:44.532430Z 0 [Note] InnoDB: Using Linux native AIO
2021-03-30T12:20:44.532739Z 0 [Note] InnoDB: Number of pools: 1
2021-03-30T12:20:44.532879Z 0 [Note] InnoDB: Using CPU crc32 instructions
2021-03-30T12:20:44.535236Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-03-30T12:20:44.546880Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-03-30T12:20:44.549449Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-03-30T12:20:44.561014Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2021-03-30T12:20:44.562673Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 12665801
2021-03-30T12:20:44.562685Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 12665810
2021-03-30T12:20:44.562690Z 0 [Note] InnoDB: Database was not shutdown normally!
2021-03-30T12:20:44.562695Z 0 [Note] InnoDB: Starting crash recovery.
2021-03-30T12:20:44.713371Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2021-03-30T12:20:44.713417Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-03-30T12:20:44.713562Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-03-30T12:20:45.454122Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2021-03-30T12:20:45.456067Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2021-03-30T12:20:45.456099Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2021-03-30T12:20:45.456761Z 0 [Note] InnoDB: Waiting for purge to start
2021-03-30T12:20:45.507075Z 0 [Note] InnoDB: 5.7.33 started; log sequence number 12665810
2021-03-30T12:20:45.507543Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2021-03-30T12:20:45.507941Z 0 [Note] Plugin 'FEDERATED' is disabled.
2021-03-30T12:20:45.511918Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210330 12:20:45
2021-03-30T12:20:45.524384Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2021-03-30T12:20:45.524418Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2021-03-30T12:20:45.526363Z 0 [Warning] CA certificate ca.pem is self signed.
2021-03-30T12:20:45.526435Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2021-03-30T12:20:45.527538Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2021-03-30T12:20:45.527717Z 0 [Note] IPv6 is available.
2021-03-30T12:20:45.527762Z 0 [Note] - '::' resolves to '::';
2021-03-30T12:20:45.527810Z 0 [Note] Server socket created on IP: '::'.
2021-03-30T12:20:45.578895Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2021-03-30T12:20:45.602259Z 0 [Note] Event Scheduler: Loaded 0 events
2021-03-30T12:20:45.602848Z 0 [Note] mysqld: ready for connections.
Version: '5.7.33' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
2021-03-30T12:20:56.582691Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2021-03-30T12:21:22.098439Z 3 [Note] Access denied for user 'dhia'@'localhost' (using password: YES)
2021-03-30T12:21:26.702866Z 4 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2021-03-30T12:21:56.174284Z 5 [Note] Access denied for user 'root'@'localhost' (using password: YES)
.env file :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=preprodica
DB_USERNAME=root
DB_PASSWORD=Str0ngDBP@ssw0rd
Docker compose :
services:
attendize_app:
build:
context: . # The path of the Dockerfile
volumes:
- .:/usr/src/app
depends_on:
- attendize_db
working_dir: /usr/src/app
environment:
SERVICE_NAME: attendize-app
DB_CONNECTION: mysql
DB_DRIVER: mysql
DB_HOST: attendize_db
DB_PORT: 3306
networks:
- app_network
attendize_nginx:
build:
context: ./docker-nginx/. # The path of the Dockerfile
volumes:
- "./public:/usr/src/app/public"
environment:
NGINX_FPM_HOST: attendize_app
NGINX_ROOT: /usr/src/app/public
ports:
- "8000:80"
depends_on:
- attendize_app
networks:
- app_network
attendize_db:
image: mysql:5
restart: always
environment:
MYSQL_DATABASE: "preprodica"
MYSQL_ROOT_PASSWORD: "Str0ngDBP@ssw0rd"
MYSQL_USER: "dhia"
MYSQL_PASSWORD: "dhia"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
ports:
- "3306:3306"
volumes:
- "./storage/db-data:/var/lib/mysql"
networks:
- app_network
networks:
app_network:
driver: bridge
2
Answers
I Fixed using :
sudo rm -r db-data/
docker-compose up -d
docker-compose down -v
Good Luck!
Docker-compose does extra work to preserve volumes between runs (thus preserving the database); you may want to try docker-compose rm -v to delete everything and try starting it up again. The command docker-compose rm -v reflects in the containers, but NOT in the volume mapped. So, the following command will remove the containers and since it doesn’t delete the volumes, the command files to create a new user.
At this point, the only way to make it right is to delete the directory that you mapped your mysql data.
Only after that, the command created a new database with the users correctly set!
You can check this link too
https://www.programmersought.com/article/16512825562/