Samer Aamar
Samer Aamar

Reputation: 1408

MySQL: how to run shell command from .SQL script file

Running with MySQL 5.6.36 on Windows 10, I am writing a script in .sql file. I need to run some shell command (in this case to concatenate two files).

How can i do it?

I tried this but it gives "compilation error":

\! ls

It says:

Syntax error: '\' escape operator is not valid input at this position

Upvotes: 2

Views: 7794

Answers (1)

wchiquito
wchiquito

Reputation: 16551

I can't reproduce the error:

File: /path/to/file/test.sql

SELECT VERSION();

SELECT 'system' `system`;
system ls -al myDir

SELECT '\\!';
\! ls -al myDir

MySQL Command Line:

mysql> \. /path/to/file/test.sql
+-----------+
| VERSION() |
+-----------+
| 5.7.11    |
+-----------+
1 row in set (0.00 sec)

+--------+
| system |
+--------+
| system |
+--------+
1 row in set (0.00 sec)

total 0
dr--------  2 user user  10 Jan 12 00:00 .
dr-------- 23 user user 280 Jan 13 23:00 ..
+----+
| \! |
+----+
| \! |
+----+
1 row in set (0.00 sec)

total 0
dr--------  2 user user  10 Jan 12 00:00 .
dr-------- 23 user user 280 Jan 13 23:00 ..

Upvotes: 1

Related Questions