I have created a shell script to connect to a DB and INSERT IPs and MACs from dhcpd.log filethe scripts worked properly:#/!bin/bash#Defining VariablesdhcpLogFile=/var/log/dhcpd.log#Begin Code# extrcting the Information of IPs and MACs from log file# and eleminating the duplicate EntryNumberOfLines=$(awk '/DHCPACK/ { print $8} ' $dhcpLogFile | awk '!x[$0]++'|awk 'BEGIN{i=0}{i++;}END{print i}')j=1while [ $NumberOfLines -gt 0 ]doip=$(awk '/DHCPACK/ { print $8} ' $dhcpLogFile | awk '!x[$0]++' |cut -f$j -d$'\n')mac=$(awk '/DHCPACK/ { print $10} ' $dhcpLogFile | awk '!x[$0]++' |cut -f$j -d$'\n')echo $ipecho $mac   let j +=1let NumberOfLines -=1mysql -u root --password='pw' MatchingDB <<- _END_ INSERT INTO IP_MACTable (IP_Address, MAC) VALUES ('$ip','$mac');_END_doneThe code is correct but as you can see it connects to the DB every insert query inside the while, my question is how can I connect to the DB only once then do multiple queries then exit without connecting to it every insertion operation 
how to Connect to Mysql only once?
linux;shell;mysql
You can do it by piping to mysql:while do        echo INSERT INTO IP_MACTable (IP_Address, MAC) VALUES ('$ip','$mac');done | mysql -u root Note how I changed your while loop to output the queries it wants to run to stdout. Then I piped your while do...done loop to mysql.You can pipe a subshell as well, so for example you could do:(    echo BEGIN;    while  ; do                echo INSERT INTO IP_MACTable (IP_Address, MAC) VALUES ('$ip','$mac');    done    echo COMMIT;) | mysql -u root so that if you abort processing in the middle MySQL will roll back the transaction, so you don't wind up with a half-loaded file. Also, running inside a transaction (as opposed to committing each row individually) is generally much faster.