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

1
  • 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 Commented Jul 17, 2020 at 6:47

1 Answer 1

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


Sign up to request clarification or add additional context in comments.

5 Comments

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
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
Can we go with chat room?
Not worked for me when I bind the volumes in mysql service in docker-compose.yml files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.