NoSQL据说就是要break these properties= =`IDK why...
SELECT attribute-expression-list FROM relation-list [ WHERE condition ];
attribute-expression-list:
relation-list:
condition:
AND | TRUE | FALSE | NULL |
TRUE | TRUE | FALSE | NULL |
FALSE | FALSE | FALSE | FALSE |
NULL | NULL | FALSE | NULL |
OR | TRUE | FALSE | NULL |
TRUE | TRUE | TRUE | TRUE |
FALSE | TRUE | FALSE | NULL |
NULL | TRUE | NULL | NULL |
NOT | TRUE | FALSE | NULL |
FALSE | TRUE | NULL |
(Q1 and Q2 must have same attribute-list)
Q1 UNION Q2 => Together all the tuples in Q1 and Q2
Q1 INTERSECT Q2 => Only tuples in both Q1 and Q2
Q1 EXCEPT Q2 => Tuples only in Q1 but not in Q2
ALL关键字: 允许重复
UNION ALL will include twice of duplicate tuples
INTERSECT ALL will include all possible pairs of match tuples, duplication possible
EXCEPT ALL will include all "not in Q2" tuples, duplication possible
SELECT ... ... ORDER BY attribute [DESC/ASC], attribute [DESC/ASC], ......
Note: 如果没有指定Order, return的数据可能是任意顺序
{count, sum, avg, min, max} => Aggregate expressions
Order: Group => Having => Aggregate
Note: 没有被group by指定的attribute不能出现在SELECT的attr-list中, 除非是aggregate
INSERT INTO relation-name [( attribute-list )] VALUE ( value-list );
DELETE FROM relation-name [ WHERE condition ];
UPDATE relation-name SET attribute-assignment-list [ WHERE condition ];
attribute-assignment-list:
CREATE TABLE relation-name ( attribute-name attribute-type [constraints-list], ... )
attribute-type: http://www.w3school.com.cn/sql/sql_datatypes.asp
constraints-list: (Constraints的格式在各种数据库中都不太一样, 就不列举了)
CREATE VIEW view-name AS ( SELECT ... )
从View SELECT的方法和table一样
CREATE TRIGGER trigger-name
AFTER UPDATE OF attribute-list ON relation-name
REFERENCING OLD as instance-name(o) NEW as instance-name(n)
FOR EACH ROW ...
不同database语法不一
]]>这个脚本来自小夜博客, 经我略加修改了一下.
下载: backup_to_mail.sh
很简单的一段bash script, 只需要自定义下mysql的用户名密码, 邮箱地址和要备份的目录.
然后进行下边的步骤:
首先要建立好放置备份文件的目录
mkdir /home/backup
然后安装发送邮件的程序
yum install sendmail mutt
把backup_to_mail.sh放到刚刚建立的目录中, 然后给脚本增加运行权限
chmod a+x /home/backup/backup_to_mail.sh
最后一步是设置定时运行, 输入
crontab -e
然后在vi编辑界面中加入下面这行文字
00 00 * * * /home/backup/backup_to_mail.sh
:x + enter就ok了.
其中00 00表示在每日00分, 00点的时候运行该脚本.
下边是脚本的内容, 以备附件失效和以后学习...
#!/bin/bash
MYSQL_USER=root #mysql username
MYSQL_PASS=*********** #mysql password
MAIL_TO=*******@***.** #mailling to
WEB_DATA=/home/wwwroot/ #to be backup dir
#define variables
DataBakName=Data_$(date +%Y%m%d).tar.gz
WebBakName=Web_$(date +%Y%m%d).tar.gz
OldData=Data_$(date -d -3day +%Y%m%d).tar.gz
OldWeb=Web_$(date -d -3day +%Y%m%d).tar.gz
DataSubject="Backup: gregwym.info database "$(date +%Y%m%d)
WebSubject="Backup: gregwym.info web dir "$(date +%Y%m%d)
#delete data from 3days earlier
rm -rf /home/backup/$OldData /home/backup/$OldWeb
cd /home/backup
#export database to compressed gz files
for db in `/usr/local/mysql/bin/mysql -u$MYSQL_USER -p$MYSQL_PASS -B -N -e 'SHOW DATABASES' | xargs`; do
(/usr/local/mysql/bin/mysqldump --single-transaction -u$MYSQL_USER -p$MYSQL_PASS ${db} | gzip -9 - > ${db}.sql.gz)
done
#compress database files
tar zcf /home/backup/$DataBakName /home/backup/*.sql.gz
rm -rf /home/backup/*.sql.gz
#mail database
echo $DataSubject | mutt -a /home/backup/$DataBakName -s "${DataSubject}" $MAIL_TO
#compress backup dir
tar zcf /home/backup/$WebBakName $WEB_DATA
#mail dir
echo $WebSubject | mutt -a /home/backup/$WebBakName -s "${WebSubject}" $MAIL_TO
echo "bye"
#END
如果不希望备份网页文件, 或者希望数据库和网页分别备份的, 可以自行拆分脚本为两个文件.
如果只是想降低备份网页文件的频率, 可以将#mail dir部分替换为:
if [ $(date +%A) = "Sunday" ]; then
echo $WebSubject | mutt -a /home/backup/$WebBakName -s "${WebSubject}" $MAIL_TO
fi
]]>