2009年5月14日星期四

crontab和mysqldump的实验

工作中用到了记录一下:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| crontest | <----这里已经创建了一个测试cron的database
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)

mysql> grant all on crontest.* to crontestuser@'%' identified by 'abc123'; <--授权 Query OK, 0 rows affected (0.01 sec) 测试 [root@CRRACTEST mysqltest]# mysql -ucrontestuser -pabc123 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.0.45 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> show tables;
ERROR 1046 (3D000): No database selected
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| crontest |
| test |
+--------------------+
3 rows in set (0.00 sec)

mysql>


--创建一个新的database,import测试使用
[root@CRRACTEST mysqltest]# mysqladmin create importtest
数据导入
[root@CRRACTEST mysqltest]# mysql importtest

数据检查
[root@CRRACTEST mysqltest]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| crontest |
| importtest | <---here
| mysql |
| test |
+--------------------+
5 rows in set (0.00 sec)

mysql> use importtest;
Database changed
mysql> show tables
-> ;
+----------------------+
| Tables_in_importtest |
+----------------------+
| crontesttab |
+----------------------+
1 row in set (0.00 sec)

mysql> select * from crontesttab;
+------+--------+
| id | name |
+------+--------+
| 1 | Leo |
| 2 | German |
| 3 | Cyrus |
| 4 | Ken |
+------+--------+
4 rows in set (0.00 sec)

mysql>




crontab用到的脚本:
*/1 * * * * /root/mysqltest/test.sh
#01 0 * * * /root/mysqltest/test.sh

test.sh
#!/bin/sh
. ~/.bash_profile
#echo databasename`date "+%Y%m%d"`
#mysqldump -ucrontestuser -pabc123 crontest >/home/crontest`date "+%Y%m%d"`.sql
mysqldump -ucrontestuser -pabc123 crontest >/root/mysqltest/crontest`date "+%Y%m%d%H%M"`.sql

以备后查!

没有评论:

发表评论