作者:邓聪聪
mysql的脚本执行
#!/bin/sh HOST="127.0.0.1" PORT="3306" UESRNAME="root" PASSWORD="123456" #DB_NAME="day1" #DB_NAME="day2" DB_NAME="day3" TABLE_NAME="logs" log=1.txt #task.log=result.log exec 2>>$log exec 1>>$log creat_db_sql="create database if not exists ${DB_NAME}" creat_table_sql="create table IF not exists ${TABLE_NAME} ( name varchar(20), id int(23) primary key auto_increment )" insert_sql="insert into ${TABLE_NAME} values('billchen',2)" select_sql="select * from ${TABLE_NAME}" update_sql="update ${TABLE_NAME} set id=3" delete_sql="delete from ${TABLE_NAME}" #creat_db_sql="create database if not exists ${DB_NAME}" mysql -h${HOST} -u${UESRNAME} -p${PASSWORD} -e "${creat_db_sql}" #creat_table_sql="create table if not exists ${TABLE_NAME} ( name varchar(20), id int(11) default 0 auto_increment=1)" mysql -h${HOST} -u${UESRNAME} -p${PASSWORD} -D ${DB_NAME} -e "${creat_table_sql}" #insert_sql="insert into ${TABLE_NAME} values('billchen',2)" mysql -h${HOST} -u${UESRNAME} -p${PASSWORD} ${DB_NAME} -e "${insert_sql}" #select_sql="select * from ${TABLE_NAME}" mysql -h${HOST} -u${UESRNAME} -p${PASSWORD} ${DB_NAME} -e "${select_sql}" mysql -h${HOST} -u${UESRNAME} -p${PASSWORD} ${DB_NAME} -e "${update_sql}" mysql -h${HOST} -u${UESRNAME} -p${PASSWORD} ${DB_NAME} -e "${delete_sql}" if [ $? == 0 ]; then echo "任务完成" else echo "任务失败" fi