MariaDB / mariadb-docker

Docker Official Image packaging for MariaDB
https://mariadb.org
GNU General Public License v2.0
770 stars 438 forks source link

Errors while restoring dump in /docker-entrypoint-initdb.d #270

Closed lonix1 closed 4 years ago

lonix1 commented 4 years ago

I want to backup and restore using a sql dump. I followed the instructions in the docs.

I created the database for use with wordpress, and created just one test page. I installed phpmyadmin to the same database.

Then I created a backup like this:

mysqldump \
  --all-databases \
  --add-drop-database --add-drop-table \
  --user=root --password=password \
  > seed.sql

Then I mounted the seed.sql dump in docker-compose.yml like this:

volumes:
  - mariadb_data:/var/lib/mysql/
  - ./seed_data/:/docker-entrypoint-initdb.d/:ro

Then I deleted the mariadb_data volume and container, and restarted the container. The database read the seed script, and seemed to restore the database.

But, the logs show this:

/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/seed.sql

[ERROR] InnoDB: Table mysql.innodb_table_stats not found.

What did I do wrong?

wglambert commented 4 years ago

What versions are you using, did you restore to a newer version of mariadb?

lonix1 commented 4 years ago

10.4.8-bionic

Same image version for backup and restore.

wglambert commented 4 years ago

Most the issues I see about that specific error InnoDB: Table mysql.innodb_table_stats not found. mention ibdata1 missing, or using an old database on a newer version.

I was able to load a backup with the instructions at https://github.com/docker-library/docs/tree/master/mariadb#restoring-data-from-dump-files Creating a database and a dump

$ docker run -d --rm --name maria -e MYSQL_ROOT_PASSWORD=root mariadb:10.1
d67d1b400ba09cab148e03cba1a9c52b1e2bd4e893dabb39d016485c8e3978ce

$ grep ready <(docker logs -f maria 2>&1)
2019-10-30 20:41:43 139958217316352 [Note] mysqld: ready for connections.
2019-10-30 20:41:52 139664121964544 [Note] mysqld: ready for connections.
^C

$ docker exec -it maria mysql -uroot -proot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.41-MariaDB-1~bionic mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database mytestdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> exit
Bye

$ docker exec maria sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > ./databases.sql

Loading the dump to a new container named maria-new

$ docker run -d --rm --name maria-new -e MYSQL_ROOT_PASSWORD=root mariadb:10.1                                          
350ef559668b7f64ed65ea272c192775da57ea1c939043cfcf560b1c205b9379

$ grep ready <(docker logs -f maria-new 2>&1)
2019-10-30 20:43:36 140617077377024 [Note] mysqld: ready for connections.
2019-10-30 20:43:41 140154845829120 [Note] mysqld: ready for connections.
^C

$ docker exec -i maria-new sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' < ./databases.sql

$ docker exec -it maria-new mysql -uroot -proot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.1.41-MariaDB-1~bionic mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| mytestdb           |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

Going to close since this is isn't an issue with the image, I would try asking over at the Docker Community Forums, Docker Community Slack, or Stack Overflow. Since these repos aren't really a user-help forum

lonix1 commented 4 years ago

Thanks for the diagnostics!

I followed your example and did not get errors. But my example does give errors.

I narrowed it down to wordpress. When it's installed, the backups contain something that causes that error. And strangely, even if I get the error, when I do a use mysql; show tables; it actually shows that innodb_table_stats does exist.