peterv6
February 15, 2011, 9:45am
1
Can someone tell me the syntax to run a shell script from within MySQL? I know there is a way to do it, but I can't remember the syntax. I thought it was something like:
mysql> \. /user/myscript;
but I get this error:
Failed to open file '/user/myscript;', error: 2
Please help!
Thanks,
Peter V.
peterv6
February 15, 2011, 10:27am
3
verdepolo, thanks for the reply. It seems to be working, but now I'm getting this message:
my script contains one line:
'show tables';
I've tried it unquoted and double quoted too.
When I try to run it, I get:
mysql> \! t2.sql;
/Users/peterv/bin/t2.sql: line 1: show tables: command not found
Running 'show tables' itself does work:
mysql> show tables;
+--------------------+
| Tables_in_project1 |
+--------------------+
| AUTHORBOOK |
| myauthors |
| mybooks |
| test_books |
+--------------------+
4 rows in set (0.00 sec)
mysql>
Any ideas what's causing my script to not work?
Thanks,
Peter V.
I thought you were trying to run unix commands from a shell script but apparently what you are trying to do is run a set of mysql instructions from a file, correct?
Use this instead:
mysql> source /user/myscript;
peterv6
February 15, 2011, 11:04am
5
Sorry for the confusion, you are correct. Both of your replies have been added to my notes, and will are extremely useful. Thank you very much!