Shell Scripting Knowledge Base

MySQL Query

Query MySQL in a shell script 1
#!/bin/bash

set -f        # disable globbing
IFS=$'\n'     # set field separator to NL (only)

result=$(mysql -u username -h localhost -p -e "USE dbname;SELECT column_name FROM table_name")
 
for i in "${result}"
do
	echo "$i" >> results.txt
done