Home > Software design >  How come mysqldump into a file doesn't work within the docker container (with an unintuitive er
How come mysqldump into a file doesn't work within the docker container (with an unintuitive er

Time:10-03

When using the mysql:5.7 docker image, I go into the docker container by doing exec -it /bin/sh to try to dump out a backup of the database. I have a volume mounted on /share, which is where I am attempting to save the dump file.

If I do the following:

mysqldump -u user -ppassword database

Then I successfully see a dump of the database being printed on the screen.

If I do the following:

echo "hello world" > /share/dump.sql

Then I successfully see the /share/dump.sql file containing hello world.

But if I try to combine that into:

mysqldump -u user -ppassword database > /share/dump.sql

Then I get a seemingly unrelated error, saying:

Error: 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation' when trying to dump tablespaces

Obviously it's not a case of missing privileges, since my mysqldump call without saving into a file works. So, what gives?

For anyone wanting to try it out, here's the relevant compose file:

version: '3.8'

services:
  db:
    image: mysql:5.7
    environment:
      MYSQL_DATABASE: database
      MYSQL_USER: user
      MYSQL_PASSWORD: password
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - ./share:/share

volumes:
  db:

CodePudding user response:

Per mysqldump reference manual on privileges require "And (as of MySQL 5.7.31) PROCESS if the --no-tablespaces option is not used".

Testing with using --no-tablespaces with:

$ podman run --rm --name mysql57 -e MYSQL_DATABASE=database \
    -e MYSQL_USER=user -e MYSQL_PASSWORD=password \
    -e MYSQL_ROOT_PASSWORD=root -d  mysql:5.7

8411383e46549f4fd028ee27d74b4799f56e4b23b63321e2e445ebd7577bf411

And the exec:

root@8411383e4654:/# mysqldump -u user -ppassword --no-tablespaces database
mysqldump: [Warning] Using a password on the command line interface can be insecure.
-- MySQL dump 10.13  Distrib 5.7.35, for Linux (x86_64)
--
-- Host: localhost    Database: database
-- ------------------------------------------------------
-- Server version   5.7.35

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE=' 00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2021-10-03  3:20:12

It's right, no errors.

  • Related