Documentation Home
MySQL Shell 8.0
Related Documentation Download this Manual
PDF (US Ltr) - 463.0Kb
PDF (A4) - 459.7Kb
HTML Download (TGZ) - 92.3Kb
HTML Download (Zip) - 103.9Kb


MySQL Shell 8.0  /  MySQL Shell Code Execution  /  Active Language

5.1 Active Language

MySQL Shell can execute SQL, JavaScript or Python code, but only one language can be active at a time. The active mode determines how the executed statements are processed:

  • If using SQL mode, statements are processed as SQL which means they are sent to the MySQL server for execution.

  • If using JavaScript mode, statements are processed as JavaScript code.

  • If using Python mode, statements are processed as Python code.

When running MySQL Shell in interactive mode, activate a specific language by entering the commands: \sql, \js, \py.

When running MySQL Shell in batch mode, activate a specific language by passing any of these command-line options: --js, --py or --sql. The default mode if none is specified is JavaScript.

Use MySQL Shell to execute the content of the file code.sql as SQL.

shell> mysqlsh --sql < code.sql

Use MySQL Shell to execute the content of the file code.js as JavaScript code.

shell> mysqlsh < code.js

Use MySQL Shell to execute the content of the file code.py as Python code.

shell> mysqlsh --py < code.py

From MySQL Shell 8.0.16, you can execute single SQL statements while another language is active, by entering the \sql command immediately followed by the SQL statement. For example:

\sql select * from sakila.actor limit 3;

The SQL statement does not need any additional quoting, and the statement delimiter is optional. The command only accepts a single SQL query on a single line. With this format, MySQL Shell does not switch mode as it would if you entered the \sql command. After the SQL statement has been executed, MySQL Shell remains in JavaScript or Python mode.