Under Linux, a shell script reads the values of each data item in the MySQL result set, reads the SQL results in rows, and reads the results of the SQL execution into the shell variable, which can then be processed.
Hostname= "172.16.xx.xx" #数据库信息
Port= "3306"
Username= "Root"
password= "Root"
Dbname= "Log" #数据库名称
Tablename= "Student"
Command1= "Mysql-h${hostname}-p${port}-u${username}-p${password} ${dbname}
Method One:
While Read-a row
Do
echo ". ${row[0]}.. ${row[1]}.. "
done< < (echo "SELECT ID, name from student;" | ${command1})
Method Two:
While read a B
Do
echo ". ${a}.. ${B}: "
done< < (echo "SELECT ID, name from student;" | ${command1})
Note: Notice "done< < ", the first "<" to and "done" no space between, two "<" there is a space between,"<" and "(" there is no space between.
The shell script reads the values of each data item in the MySQL result set