My task was to use docker to wrap my application from the database into containers. phpMyAdmin was used to monitor the database. Final stack: MySQL + Docker + phpMyAdmin + Java + Hibernate.
My docker-compose.yml file:
version: "3"
services:
db:
image: mysql:8.0.18
restart: always
environment:
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: usersDB
ports:
- '3306:3306'
volumes:
- mysql-data:/var/lib/mysql
phpmyadmin:
image: phpmyadmin:latest
restart: always
ports:
- '8080:80'
environment:
- PMA_ARBITRARY=1
volumes:
mysql-data:
hibernate.cfg.xml file:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost:3306/usersDB?createDatabaseIfNotExist=true</property>
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
</session-factory>
</hibernate-configuration>
After running the program and checking the operation of the database, it turns out that the data is written locally in MySQL Workbench, and not on phpMyAdmin. Absolutely empty.