首页 > 代码库 > shell脚本操作数据库

shell脚本操作数据库

#!/bin/bash


HOST_NAME="localhost"
PORT=3306
USERNAME="root"
PASSWORD="root"
DBNAME="test"
TABLENAME="tb_test"


today=`date +%Y-%m-%d`


#删除数据
delete_sql="delete from ${TABLENAME} where todaytime!= ‘${today}‘"
mysql -h${HOST_NAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${delete_sql}"