docker-compose exec mysql sh 'mysql -uroot -pSECRET' > all-databases.sql
root@OrangePi:~# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4aa203b3e9c4 web_ddns "docker-entrypoint.s…" 4 weeks ago Up 12 days web_ddns_1
800b7d624914 nginx:latest "nginx -g 'daemon of…" 4 weeks ago Up 4 days 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp web_nginx_1
cdebc683a127 mhzawadi/phpmyadmin:latest-arm64v8 "/docker-entrypoint.…" 4 weeks ago Up 4 weeks 80/tcp web_phpmyadmin_1
96403bc827ac web_fpm "docker-php-entrypoi…" 4 weeks ago Up 4 weeks 9000/tcp web_fpm_1
11ccfb5364fe mariadb "docker-entrypoint.s…" 4 weeks ago Up 4 weeks 0.0.0.0:3306->3306/tcp web_mysql_1
root@OrangePi:~# docker exec -it web_mysql_1 mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6272
Server version: 10.4.11-MariaDB-1:10.4.11+maria~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)]>
docker exec -it web_mysql_1 mysql -uroot -p
то он спрашивает пароль и после ввода открывается консоль и все работает. root@OrangePi:~# docker exec -it web_mysql_1 mysql -uroot -pSECRET
> help
> some
>
root@OrangePi:~# docker exec -it web_mysql_1 mysql -uroot -pSECRET -e "query"
>
> nothing
>
>
docker exec -it mysql-server mysql -P 3306 -h localhost -uroot -ppassword -e "set @var = '1'; select @var ;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+------+
| @var |
+------+
| 1 |
+------+
root@OrangePi:~# docker exec -it web_mysql_1 mysql -P 3306 -h localhost -uroot -pSECRET -e "set @var = '1'; select @var ;"
>
>
> to nothing
>
>
>
docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f9fcbc9baed1 mysql:5.7 "docker-entrypoint.s…" 11 minutes ago
docker exec -it mysql-server mysql -P 3306 -h localhost -uroot -ppassword -e "set @var = '1'; select @var ;"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
и тишинаServer] /usr/sbin/mysqld: ready for connections. Version: '8.0.18' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
docker exec ...
используйте docker exec -it ...