简体   繁体   中英

using docker and mysql to import the file?

I am using a mysql docker container to load the database data, the database folder containers multiple files shown as

在此处输入图像描述

employees.sql has the following commands

SELECT 'LOADING departments' as 'INFO';
source load_departments.dump ;
SELECT 'LOADING employees' as 'INFO';
source load_employees.dump ;
SELECT 'LOADING dept_emp' as 'INFO';
source load_dept_emp.dump ;
SELECT 'LOADING dept_manager' as 'INFO';
source load_dept_manager.dump ;
SELECT 'LOADING titles' as 'INFO';
source load_titles.dump ;
SELECT 'LOADING salaries' as 'INFO';
source load_salaries1.dump ;
source load_salaries2.dump ;
source load_salaries3.dump ;

right now I am using the docker to do so with the following orders.

  1. First, check and copy the container ID for your MySQL docker by:

     sudo docker ps docker id is 3a66701bd013, name is mysql
  2. Copy the SQL dump file directory and the file into the container using:

    docker cp /Users/xisizhe/Downloads/test_db-master/ mysql:/

  3. Now to interact with MySQL inside a running container run the following command:

    docker exec -it mysql mysql -uroot -p

  4. Now import the file by typing:

    source employees.sql

it works to import employees.sql, but it fails to import the other sql files and dump files.

ERROR: 
Failed to open file 'load_salaries1.dump', error: 2
ERROR: 
Failed to open file 'load_salaries2.dump', error: 2
ERROR: 
Failed to open file 'load_salaries3.dump', error: 2
ERROR: 
Failed to open file 'show_elapsed.sql', error: 2

any problems for my procedure? thanks in advance.

if you execute the following command

docker cp /Users/xisizhe/Downloads/test_db-master/ mysql:/

you should add the /test_db-master/ before those dump files inside the employees.sql like:

source /test_db-master/load_departments.dump ;
source /test_db-master/load_employees.dump ;
...

Then, you can import the sql data using the commands:

docker exec -i mysql mysql -uroot -p1234  < employees.sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM