killerxf 发表于 2018-8-29 09:14:46

mysql下通过shell脚本插入数据

#!/bin/bash  
>test_new
  
read -p "please enter you mysql password:" passwd
  
MYSQL=/usr/bin/mysql
  
TABLE="dic"
  
TIME=`date +%F\ %T`
  
P="\e[01;35m"
  
#sed "s/\(^.*$\)/\1,$TIME/" test >> test_new##在每行行尾添加时间
  
cat test1 | sed 's/^/NULL\t/g' |sed 's/\t/,/g' |sed "s/\(^.*$\)/\1,$TIME/" >>test_new
  
cat test_new |while read line
  
#echo "$TIME" >>mysql_err_log
  
do
  
echo $line
  
query=`echo "$line" |awk -F ","'{ printf("%s,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"", $1, $2, $3, $4, $5, $6, $7 , $8)}'`
  
echo $query 1>>mysql_err_log 2>&1
  
echo $query
  
$MYSQL dic -u root -p$passwdmysql_err_log


页: [1]
查看完整版本: mysql下通过shell脚本插入数据