crontab插入mysql乱码
我想用MYSQL记录一些城市的每天天气情况,数据是从中国天气网获取,通过脚本格式化数据
mysql -e 插入到数据库
数据库结构
mysql> desc weather;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| cityid | int(10) | NO | | NULL | |
| city | varchar(20) | NO | | NULL | |
| time | datetime | NO | | NULL | |
| temperature | varchar(10) | NO | | NULL | |
| windspeed | varchar(20) | NO | | NULL | |
| humidity | varchar(10) | YES | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
7 rows in set (0.01 sec)
数据库查询
mysql> select * from weather;
+----+-----------+---------------+---------------------+-------------+-----------------------------+----------+
| id | cityid | city | time | temperature | windspeed | humidity |
+----+-----------+---------------+---------------------+-------------+-----------------------------+----------+
| 1 | 101010100 | 北京 | 2014-09-18 20:20:14 | 21 | 西南风|2级 | 67% |
| 2 | 101020100 | 上海 | 2014-09-18 20:20:14 | 19 | 西北风|1级 | 89% |
| 3 | 101220101 | 合肥 | 2014-09-18 20:20:14 | 19 | 东风|2级 | 86% |
| 4 | 101220105 | 巢湖 | 2014-09-18 20:20:14 | 18 | 东南风|1级 | 92% |
| 5 | 101280601 | 深圳 | 2014-09-18 20:20:14 | 32 | 西南风|1级 | 60% |
| 6 | 101010100 | 乱码 | 2014-09-18 20:21:01 | 21 | 乱码 | 66% |
| 7 | 101020100 | 乱码 | 2014-09-18 20:21:01 | 19 | 乱码 | 89% |
| 8 | 101220101 | 乱码 | 2014-09-18 20:21:01 | 19 | 乱码 | 86% |
| 9 | 101220105 | 乱码 | 2014-09-18 20:21:01 | 18 | 乱码 | 91% |
| 10 | 101280601 | 乱码 | 2014-09-18 20:21:01 | 33 | 乱码 | 62% |
其中
id 1-5是手动运行脚本(/bin/sh /root/geweather.sh)数据
id 6-10是crontab运行脚本导入的值,乱码不让上传,图片也被封了,用“乱码代替了”
crontab配置
*/1 * * * * root /bin/sh /root/weather/getweather.sh > /dev/null 2>&1
现在的情况就是我手动运行/bin/sh /root/weather/getweather.sh > /dev/null 2>&1插入数据中文可以显示
crontab执行中文就变成乱码了