As well as interactive code execution, MySQL Shell provides batch code execution from:
A file loaded for processing.
A file containing code that is redirected to the standard input for execution.
Code from a different source that is redirected to the standard input for execution.
Loading SQL code from a file for batch processing.
mysqlsh --file code.js
Redirecting a file to standard input for execution.
mysqlsh < code.js
Redirecting code to standard input for execution.
echo "show databases;" | mysqlsh --sql --uri email@example.com:33060
Starting with version 1.0.4, on Linux you can create executable
scripts that run with MySQL Shell by including a
#! line as the first line of the script. This
line should provide the full path to MySQL Shell and include
--file option. For example:
#!/usr/local/mysql-shell/bin/mysqlsh --file print("Hello World\n");
The script file must be marked as executable in the filesystem. Running the script invokes MySQL Shell and it executes the contents of the script.