mysql简单脚本

db.sh

#!/bin/bash
#

user="tercher"
password="123456"
database="$1"
SQL="$2"

mysql -uteacher -p"$password" -D "$database" -N -B -e "$SQL"

命令行我就可以直接指定数据库执行SQL语句了

sh db.sh student "select * from employee" 

我们也可以将查询的结果直接保存在文件中

sh db.sh student "select * from employee" >> result.txt

  

猜你喜欢

转载自www.cnblogs.com/soymilk2019/p/13197330.html