Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MySQL/Linux: Multiple Queries from BASH

Posted on 2011-09-08
2
Medium Priority
?
656 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
pilson66 earned 1000 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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.:
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

604 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