Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
content:serverbasics:docker-mariadb [2023/12/29 16:29] – Daniel | content:serverbasics:docker-mariadb [2025/03/29 19:46] (aktuell) – Daniel | ||
---|---|---|---|
Zeile 12: | Zeile 12: | ||
* Using Sockets, not TCP/IP on the host | * Using Sockets, not TCP/IP on the host | ||
* Added some tweaks from the net | * Added some tweaks from the net | ||
+ | |||
+ | ====== STOP ====== | ||
+ | |||
+ | This - it turned out is a very bad idea. MariaDB on Docker performs VERY bad. So i would strongly not advise to use Docker for this. Use native mariadb on your host and adept what is written here. | ||
+ | |||
+ | When you link the native mariadb- Socket to the services like this, you will be able to use Mariadb: | ||
+ | < | ||
+ | |||
+ | volumes: | ||
+ | #Bind mount: Socketfile needs to be definied by full filename, not only path! | ||
+ | - / | ||
+ | |||
+ | </ | ||
+ | |||
+ | Or you can use Port 3306 and as host your servername (NOT localhost). | ||
===== Create Socket in tmpfs ===== | ===== Create Socket in tmpfs ===== | ||
Zeile 18: | Zeile 33: | ||
Create the File ''/ | Create the File ''/ | ||
- | < | ||
+ | < | ||
#Type Path Mode UID GID Age Argument | #Type Path Mode UID GID Age Argument | ||
d / | d / | ||
</ | </ | ||
+ | |||
===== Yaml and .env, configuration of mariadb and phpMyAdmin ===== | ===== Yaml and .env, configuration of mariadb and phpMyAdmin ===== | ||
Zeile 76: | Zeile 92: | ||
# memlock: " | # memlock: " | ||
| | ||
- | test: healthcheck.sh | + | test: healthcheck.sh --connect --innodb_initialized |
| | ||
| | ||
Zeile 249: | Zeile 265: | ||
$cfg[' | $cfg[' | ||
# | # | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Backup ===== | ||
+ | |||
+ | Backing up MariaDB on Docker works like this: | ||
+ | |||
+ | < | ||
+ | #!/bin/bash | ||
+ | # This would be Postgres - i don't like postgres, so see beneath for mariadb: | ||
+ | # rm / | ||
+ | # docker exec -t postgresql-pgsql_db-1 pg_dumpall -c -U postgres | ||
+ | # For mariadb use mariadb-dump and root | ||
+ | # For mysql use mysqldump and admin | ||
+ | BACKUPFILE=/ | ||
+ | MARIADB_PASS=' | ||
+ | echo " | ||
+ | rm ${BACKUPFILE} | ||
+ | docker exec -t mariadb-mariadb-1 mariadb-dump --all-databases --single-transaction --quick --lock-tables=false -u root -p${MARIADB_PASS} | ||
+ | echo ' | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== No Docker Service ==== | ||
+ | |||
+ | If you have MariaDB as native Host- Service installed, use: | ||
+ | < | ||
+ | |||
+ | #!/bin/bash | ||
+ | # Makes a Backup of the whole Mariadb | ||
+ | BACKUPFILE=/ | ||
+ | echo " | ||
+ | # Keep one Copy of the old Backup | ||
+ | if [ -f ${BACKUPFILE} ]; then | ||
+ | if [ -f ${BACKUPFILE}.back ]; then | ||
+ | rm ${BACKUPFILE}.back | ||
+ | fi | ||
+ | mv ${BACKUPFILE} ${BACKUPFILE}.back | ||
+ | else | ||
+ | echo "File ${BACKUPFILE} was not found, not removing ${BACKUPFILE}.back" | ||
+ | fi | ||
+ | # for mysql use mysqldump... | ||
+ | / | ||
+ | if [ ! -f ${BACKUPFILE} ]; then | ||
+ | echo " | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Optimizing Tables ===== | ||
+ | |||
+ | Doing this will remove defragmentation and repair some stuff, so maybe you want to do this once a month or so '' | ||
+ | < | ||
+ | |||
+ | #!/bin/bash | ||
+ | #Optimize Database | ||
+ | # 28.11.2023: Docker-Version | ||
+ | # 13.12.2023: Replaced mysql by mariadb | ||
+ | # | ||
+ | echo "Check and optimize DB Mysql" | ||
+ | |||
+ | RUN_SQL=/ | ||
+ | RUN_LOG=/ | ||
+ | |||
+ | # | ||
+ | SQL=" | ||
+ | SQL=" | ||
+ | SQL=" | ||
+ | SQL=" | ||
+ | |||
+ | MARIADB_USER=' | ||
+ | MARIADB_PASS=' | ||
+ | CONTAINERNAME=' | ||
+ | |||
+ | RUN_CMD=" | ||
+ | |||
+ | # Create SQL Commands to run | ||
+ | ${RUN_CMD} -ANe" | ||
+ | # Execute CHECK TABLE Commands | ||
+ | ${RUN_CMD} --raw --silent --table < | ||
+ | |||
+ | #cat " | ||
+ | # | ||
+ | RUN_ERROR=(`cat " | ||
+ | if [[ ! -z " | ||
+ | echo " | ||
+ | echo "" | ||
+ | echo "!!!! ERROR- STOP OPTIMIZE: Some MySQL Databases are corrupt, please check output in ${RUN_LOG}:" | ||
+ | cat " | ||
+ | echo "" | ||
+ | echo " | ||
+ | exit 1 | ||
+ | fi | ||
+ | echo "Check MysqlDB was sucessful, no errors found" | ||
+ | |||
+ | exit 0 | ||
+ | |||
+ | #For me, i choose to run this only every 6th of the month | ||
+ | ifStart=`date ' | ||
+ | if [ $ifStart == 06 ] | ||
+ | then | ||
+ | echo " | ||
+ | RUN_SQL=/ | ||
+ | RUN_LOG=/ | ||
+ | |||
+ | SQL=" | ||
+ | SQL=" | ||
+ | SQL=" | ||
+ | SQL=" | ||
+ | |||
+ | # Create SQL Commands to run | ||
+ | ${RUN_CMD} -ANe" | ||
+ | |||
+ | # Execute Commands | ||
+ | ${RUN_CMD} --raw --silent --table <" | ||
+ | cat " | ||
+ | RUN_ERROR=(`cat " | ||
+ | if [[ ! -z " | ||
+ | echo " | ||
+ | echo "" | ||
+ | echo "!!!! ERROR- STOP OPTIMIZE: Some MySQL Databases are corrupt, please check output in ${RUN_LOG}:" | ||
+ | echo "" | ||
+ | echo " | ||
+ | exit 1 | ||
+ | fi | ||
+ | # Useless for Docker... | ||
+ | # /sbin/btrfs filesystem defragment / | ||
+ | fi | ||
+ | echo " | ||
+ | exit 0 | ||
+ | |||
+ | #Diese Version geht leider nicht, weil die KOmmandos im Docker nicht vorhanden sind... | ||
+ | #docker exec -t mysql-mysqldb-1 mysqlcheck -u admin -p' | ||
+ | #docker exec -t mysql-mysqldb-1 mysqlcheck -u admin -p' | ||
</ | </ | ||