Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing unix commands from mysql

Tags:

php

mysql

When I am running mysql in the terminal

I can do something like \! python ~/run.py to run the the file.

However when I copy this to php and do mysql_query it doesnt work.

like image 496
tomwu Avatar asked Apr 17 '26 11:04

tomwu


2 Answers

You cannot run any of the \ prefix mysql commands in PHP's mysql_query.

Only valid SQL commands can be used.

like image 107
ocodo Avatar answered Apr 19 '26 23:04

ocodo


You can't do that.

The \! commands in the MySQL Console are provided by the Console itself, not by the MySQL server proper. In other words, these commands are not sent to the MySQL server, but they are passed to the shell from which the console was launched (e.g. bash). This is a convenience shortcut, but won't work with normal SQL commands.

like image 25
Piskvor left the building Avatar answered Apr 20 '26 00:04

Piskvor left the building