I have created a shell script to connect to a DB and INSERT IPs and MACs from dhcpd.log file:#/!bin/bashdhcpLogFile=/var/log/dhcpd.logNumberOfLines=$(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')   let j +=1let NumberOfLines -=1mysql -u root --password='pw' MatchingDB <<- _END_ INSERT INTO IP_MACTable (IP_Address, MAC) VALUES ('$ip','$mac');_END_donemy question is how to modify the insert query above to let it replace an existing record when the ip attribute is duplicated and to insert a new record normally when the ip attribute isn't duplicated ?I have tried something like this but it keeps return an error (syntax error):INSERT INTO IP_MACTable (IP_Address, MAC) VALUES ('$ip','$mac') ON DUPLICATE KEY UPDATE MAC = VALUES('$mac')the error according to my server is near '$mac') Error code is #1064
how can I replace a record in my DB (mySql) by new record?
linux;shell;mysql
You can modify your insert to something like,INSERT INTO IP_MACTable (IP_Address, MAC) VALUES ('$ip','$mac') ON DUPLICATE KEY UPDATE MAC = VALUES('$mac')