Solved

MySQL/Linux: Multiple Queries from BASH

Posted on 2011-09-08
2
645 Views
Last Modified: 2012-06-27
Using BASH on Linux I want to run the following MySQL queries:
# Host: abc.example.com
# Username: ujm
# Password: p123
# Database: ujm_d

DELETE a FROM Group_Members a inner join Member b ON a.MemberID = b.ID  WHERE (a.GroupID = '27' OR a.GroupID = '26' OR a.GroupID = '25' OR a.GroupID = '24' OR a.GroupID = '22' ) AND b.UserSuspended = '1'
INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '18', `ID` from `Member` WHERE `UserSuspended` = '1'
INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '27', `ID` from `Member` WHERE `UserSuspended` != '1' AND `PremPlusMember` = '1' AND `PremWebMember` = '1' AND `SMSMember` = '1'
INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '26', `ID` from `Member` WHERE `UserSuspended` != '1' AND `PremPlusMember` = '1' AND `PremWebMember` = '1' AND `SMSMember` != '1'
INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '25', `ID` from `Member` WHERE `UserSuspended` != '1' AND `PremPlusMember` != '1' AND `PremWebMember` = '1' AND `SMSMember` = '1'
INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '24', `ID` from `Member` WHERE `UserSuspended` != '1' AND `PremPlusMember` != '1' AND `PremWebMember` != '1' AND `SMSMember` = '1'
INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '22', `ID` from `Member` WHERE `UserSuspended` != '1' AND `PremPlusMember` != '1' AND `PremWebMember` = '1' AND `SMSMember` != '1'

Open in new window

0
Comment
Question by:hankknight
2 Comments
 
LVL 8

Accepted Solution

by:
pilson66 earned 250 total points
ID: 36503854
echo "DELETE a FROM Group_Members a inner join Member b ON a.MemberID = b.ID  WHERE (a.GroupID = '27' OR a.GroupID = '26' OR a.GroupID = '25' OR a.GroupID = '24' OR a.GroupID = '22' ) AND b.UserSuspended = '1'" | mysql -uujm -pp123 -Dujm_d

then the same principe for each query
0
 
LVL 38

Assisted Solution

by:wesly_chen
wesly_chen earned 250 total points
ID: 36504608
Usage:
mysql -u ujm -p p123 -h abc.example.com  -D ujm_d  -e "MYSQL QUERY ; "

mysql -u ujm -p p123 -h abc.example.com  -D ujm_d  -e "DELETE a FROM Group_Members a inner join Member b ON a.MemberID = b.ID  WHERE (a.GroupID = '27' OR a.GroupID = '26' OR a.GroupID = '25' OR a.GroupID = '24' OR a.GroupID = '22' ) AND b.UserSuspended = '1'; "

mysql -u ujm -p p123 -h abc.example.com  -D ujm_d  -e "INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '18', `ID` from `Member` WHERE `UserSuspended` = '1' ; "

or combine then into one with ";" to separate them

mysql -u ujm -p p123 -h abc.example.com  -D ujm_d  [b]-e[/b] "INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '27', `ID` from `Member` WHERE `UserSuspended` != '1' AND `PremPlusMember` = '1' AND `PremWebMember` = '1' AND `SMSMember` = '1'; 
INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '26', `ID` from `Member` WHERE `UserSuspended` != '1' AND `PremPlusMember` = '1' AND `PremWebMember` = '1' AND `SMSMember` != '1'; 
INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '25', `ID` from `Member` WHERE `UserSuspended` != '1' AND `PremPlusMember` != '1' AND `PremWebMember` = '1' AND `SMSMember` = '1' ;
INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '24', `ID` from `Member` WHERE `UserSuspended` != '1' AND `PremPlusMember` != '1' AND `PremWebMember` != '1' AND `SMSMember` = '1' ; 
INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '22', `ID` from `Member` WHERE `UserSuspended` != '1' AND `PremPlusMember` != '1' AND `PremWebMember` = '1' AND `SMSMember` != '1' ; "

Open in new window

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question