1

I have tried all the solutions which given followed link: Solution link But I failed.

I have exec mysql instance with docker

Code Absolute path mysql> source D:\dc@vsw\XXXX\suranabr_dev01_1.sql

Error Failed to open file 'D:\dc@vsw\XXXX\suranabr_dev01_1.sql', error: 2

Vickysw
  • 70
  • 10
  • Also this command is not worked for me. `$ docker exec -i some-mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' < /some/path/on/your/host/all-databases.sql ` – Vickysw Jul 17 '20 at 06:47

1 Answers1

2

Why are you not placing the backupfile.sql in dockerfile so it will be restored automatically once the container is up?

FROM mysql
COPY backupfile.sql  /docker-entrypoint-initdb.d/

When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d

mysql-docker-Initializing a fresh instance

OR

docker exec -i mysql-container mysql -uuser -ppassword name_db < backup.sql

Import data.sql MySQL Docker Container

Or with docker-compose

version: '3.1'

services:

  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    volumes:
      - $PWD/backup.sql : /docker-entrypoint-initdb.d/backup.sql
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: test


Adiii
  • 54,482
  • 7
  • 145
  • 148
  • I can not put into docker-compose files because database restoration is only one time process... And for `docker exec -i mysql-container mysql -uuser -ppassword name_db < backup.sql` Its show me error **At line:1 char:81 + ... l-server-80 sh -c 'exec mysql -uroot -proot suranabr_dev01' < D:\dc@v ... + ~ The '<' operator is reserved for future use. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : RedirectionNotSupported** – Vickysw Jul 17 '20 at 05:32
  • the dockerfile also only write once if mount directory to `/var/lib/mysql` or database path. if database already exist it will not overide the existing one – Adiii Jul 17 '20 at 05:38
  • Can we go with chat room? – Vickysw Jul 17 '20 at 05:39
  • https://chat.stackoverflow.com/rooms/218003/room-for-adiii-and-vickysw – Adiii Jul 17 '20 at 05:44
  • Not worked for me when I bind the volumes in mysql service in docker-compose.yml files – Vickysw Jul 17 '20 at 06:40