0

I'm trying to automate these steps that I'm doing manually:

# Go into the container
docker exec -it mysql-container sh

# Log into MySQL
mysql -u root -ptest

# Specify the database
USE mydatabase;

# Call procedure_1
CALL procedure_1();

# Call procedure_2
CALL procedure_2();

My first approach was:

docker exec mysql-container mysql -u root -ptest -e "USE mydatabase; CALL procedure_1(); CALL procedure_2();"

I got an error that said procedure_1 doesn't exist. I looked around and found this answer so I updated my script to:

docker exec mysql-container mysql -u root -ptest -e "DELIMITER # USE mydatabase# BEGIN CALL procedure_1(); CALL procedure_2(); END# DELIMITER ;"

However this didn't seem to run at all, I didn't get any feedback. How do I call multiple MySQL stored procedures using docker exec?

6
  • Did you start the container with a published port? If so, can you run mysql -h 127.0.0.1 mydatabase on the host, without using the docker exec debugging tool? Commented Feb 29, 2024 at 22:23
  • @DavidMaze port mapping is defined as 3307:3306. Commented Feb 29, 2024 at 22:27
  • 1
    Did you create the procedure before calling it? Commented Feb 29, 2024 at 22:39
  • FWIW, it's not easy to use DELIMITER on the command-line, because it always interprets the rest of the current line as the delimiter string. Also you can't use BEGIN in MySQL except inside the body of stored routines. Commented Feb 29, 2024 at 22:40
  • 1
    I would take the hint from the 1st error message! You need to create that stored procedure first! Commented Feb 29, 2024 at 23:15

0

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.