---
title: "Shell 定时更新数据库功能"
author: "labreeze"
date: "2015-04-05T22:43:34Z"
tags: []
categories: ["操作系统"]
slug: "shell"
draft: false
lastmod: "2015-12-18T18:12:32Z"
id: 2199519
url: "https://labreeze.iteye.com/blog/2199519"
---

1.定时更新数据库功能

```
#!/bin/sh

i=1;
while(($i<100));do
        dateTime=$(date +'%Y-%m-%d %H:%M:%S')
        sql="update mytable  set gmt_created='$dateTime' where custins_id >= 123971  and custins_id<= 123981;"
        #将sql内容写入文件中
        echo $sql > sql
        #从文件中执行SQL
        $(mysql -umytest -pmytest -hlocalhost -P3306 mytest < sql)
        sleep 1800
done
```