PDA

View Full Version : [SOLVED] Help with shell script



Spikerok
November 28th, 2009, 12:00 AM
Target to make script which will create mysql user.
I have mysql commands


mysql -u userName -p

insert into db (host, db, user, select_priv) values ('localhost', 'customers', 'kayon', 'Y');


Im not sure how to combine it in to shell script.
Please help..

korvirlol
November 28th, 2009, 12:19 AM
you could put it into a .sql file and do something like:


mysql -u username -ppassword databasename < script.sql

note the spacing on the password switch

carl.davis
November 28th, 2009, 12:22 AM
You should also be able to do the following:


mysql -u userName -ppassword -e 'insert into tablename (host, db, user, select_priv) values ('localhost', 'customers', 'kayon', 'Y')' databasename

Spikerok
November 28th, 2009, 12:38 AM
can't believe that it's so simple...
Is their any thing alse I should include?

korvirlol
November 28th, 2009, 12:54 AM
It would be better to handle database scripts with a python or php script... but that way works fine too

Spikerok
November 28th, 2009, 01:40 AM
I will be using PHP to give values to shell script.
User will enter data in browser which will transferred to script.
Script will start and complete given task.

carl.davis
November 28th, 2009, 02:14 PM
I will be using PHP to give values to shell script.
User will enter data in browser which will transferred to script.
Script will start and complete given task.

There is no reason to do it that way. PHP can do those things directly without having to call a shell script. Just search for "PHP MySQL" and you will find lots of great tutorials with simple examples.