方法1.需要,自动登录mysql(root:root,passwd:123456),查询test库,test1表里的user=aa的记录.
#!/bin/sh
mysql -uroot -p123456 <
use test;
select * from testaa while a=10000; ###1000 not usr single quote mark,because a is int
# type,only char type need single quote mark.
exit
EOF
方法2:用expect脚本
3
1 #!/bin/bash
2 #batch_connect.sh
3
4 #cat /dev/null > batch_file
5 echo "use oss_platform;" > batch_file
6
7 URL_list=`cat url_for_db_final`
8 for URL in $URL_list
9 do
10 echo "update pornURL set count=count+1 where url=\"$URL\";" >> batch_file
11 echo "insert into pornURL (url,count) select \"$URL\",1 from dual where not exists (select * from pornURL where
url=\"$URL\");" >> batch_file
12
13 done
14 echo "exit" >> batch_file
15
16
17 cat /dev/null > url_for_db_final
18 mysql -h localhost -u ******* -p*************< batch_file | more
19
20
21 cat /dev/null > batch_file