#!/bin/bashfunction usage { echo "Usage: $0 [options] -h host --optional -p port --optional -u user -p Password -d dbname -t tablename -o outputfile "}if [ $# -lt 1 ]then usageelse while getopts "H:p:u:p:D:t:o: " opt; do case ${ OPT}&NBSP;IN&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;H) host=${OPTARG} ;; o) outfile=${OPTARG} ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;P) port=${OPTARG} ;; u) user=${OPTARG} ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;P) passwd=${OPTARG} ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;D) dbname=${OPTARG} ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;T) tablename=${OPTARG} ;; esac donefihost=${host:-localhost}port=${ Port:-3306}mysql= "MYSQL&NBSP;-H&NBSP;${HOST}&NBSP;-P&NBSP;${PORT}&NBSP;&NBSP;-U&NBSP;${USER}&NBSP;-P${PASSWD} -ane "query=" Select column_name, column_type, is_nullable, column_comment from information_schema.columns WHERE table_schema = ' ${dbname} ' and table_name = ' ${tablename} ' "Value=$ (${mysql} " ${query} ") echo ' ${value} ' |awk ' {out= '"; for (i=4; i<=nf;i++) {out=out " " $i};p rint $1 "\ t" $ "t" $ "\ T" OutFile ".csv#echo " ${value} "|awk ' {out=" "; for (i=4; i<=nf;i++) {out=out" "$i};p rint $1", "$ $", "$ $", "out}" >> test1.csv
This article from "The Dark before Dawn" blog, declined reprint!
Shell export MySQL data into CSV format