本篇文章主要介绍了"Shell脚本中执行sql语句,操作mysql数据库",主要涉及到方面的内容,对于MySql感兴趣的同学可以参考一下:
对于自动化运维,诸如备份恢复之类的,DBA经常需要将SQL语句封装到shell脚本。本文描述了在Linux环境下mysql数据库中,shell脚本下调用sql语...
[root@SZDB ~]
# more /tmp/temp.log
Logging to
file
'/tmp/temp.log'
id
val
1 jack
2 robin
3 mark
Outfile disabled.
4、shell脚本中MySQL提示符下调用SQL
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [root@SZDB ~] # more shell_call_sql2.sh
#!/bin/bash
mysql -uroot -p123456 <<>
source /root/temp .sql;
select current_date();
delete from tempdb.tb_tmp where id =3;
select * from tempdb.tb_tmp where id =2;
EOF
exit ;
[root@SZDB ~] # ./shell_call_sql2.sh
Logging to file '/tmp/temp.log'
id val
1 jack
2 robin
3 mark
Outfile disabled.
current_date()
2014-10-14
|