1

I have MariaDB (foobar_db) running in local environment in Docker. I have a SQL file some_sql_dump.sql that I want to run on this database. This is what I tried:

docker exec -t container_id_here mysql -u root -prootpass foobar_db < some_sql_dump.sql

This takes me into MariaDB's monitor:

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A                     
                                                                                   
Welcome to the MariaDB monitor.  Commands end with ; or \g.                        
Your MariaDB connection id is 11                                                   
Server version: 10.4.13-MariaDB-1:10.4.13+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 [foobar_db]> 

It seems like using the arrow (<) to pass in input from some_sql_dump.sql did not work correctly. Why did the arrow not work, and how can I make it run the SQL from the file?

cheryllium
  • 430
  • 4
  • 15

1 Answers1

1

I have just used the "--interactive , -i" option and it seems to work.

$ docker exec -i {container_id} mysql -u root -prootpass foobar_db < some_sql_dump.sql
  • Thanks - do you have any insight as to why this works but what I did doesn't work? – cheryllium Jan 11 '21 at 20:31
  • 1
    Your welcome, cheryllium! The accepted answer in this question looks to address the options usage correctly: https://stackoverflow.com/questions/30137135/confused-about-docker-t-option-to-allocate-a-pseudo-tty – Heron Fonsaca Jan 11 '21 at 21:13
  • 1
    If you don't run with `-i`, no stdin is attached. If you run with `-it`, you'll get the error message `the input device is not a TTY`. – Chris Midgley Jan 12 '21 at 08:46