2

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

4
  • why do you think that it is possible to call shell from sql? Commented Jul 18, 2017 at 20:58
  • What operating system are you using?. Commented Jul 18, 2017 at 21:16
  • i am using Windows 10 with MySQL 5.6.36. The question was updated as well Commented Jul 19, 2017 at 5:00
  • The system (\!) command works only in Unix., see 4.5.1.2 mysql Commands. Try using Windows Subsystem for Linux (WSL), see Windows 10 Installation Guide. Commented Jul 19, 2017 at 6:00

1 Answer 1

1

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 ..
Sign up to request clarification or add additional context in comments.

3 Comments

Can it be related to the version? I still see the error: | VERSION() | | 5.6.36-log | ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'system ls -al myDir SELECT '\\!'' at line 1 ERROR: Unknown command '\!'. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\! ls -al myDir' at line 1
@SamerAamar: This may be related to the version of your operating system.
maybe it is related to operating system. issue was not resolved yet, so i had to implement it in total other way. Thanks!

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.