-- 查询ecard库中有触发器的表名称
select DISTINCT EVENT_OBJECT_TABLE from information_schema.`TRIGGERS` where EVENT_OBJECT_SCHEMA = "ecard";
-- 查询ecard库中无触发器的表名称
select A.TABLE_NAME from information_schema.`TABLES` A LEFT JOIN information_schema.`TRIGGERS` B ON A.TABLE_NAME=B.EVENT_OBJECT_TABLE where B.EVENT_OBJECT_TABLE is null and A.TABLE_SCHEMA="ecard";
-- 美化
select A.TABLE_NAME from information_schema.`TABLES` A LEFT JOIN information_schema.`TRIGGERS` B ON A.TABLE_NAME = B.EVENT_OBJECT_TABLE where B.EVENT_OBJECT_TABLE IS NULL AND A.TABLE_SCHEMA = "ecard";
备份所有不带触发器的表:
# 清空backup.sql
echo > backup.sql
# 备份ecard库各表
/usr/local/mysql/bin/mysql -h 127.0.0.1 -uroot -pmysql -P 3306 ecard -e 'SELECT A.TABLE_NAME from information_schema.TABLES A LEFT JOIN information_schema.TRIGGERS B ON A.TABLE_NAME=B.EVENT_OBJECT_TABLE where B.EVENT_OBJECT_TABLE is null and A.TABLE_SCHEMA="ecard";' | grep -v TABLE_NAME | grep -v test | xargs -I {} /usr/local/mysql/bin/mysqldump -h 127.0.0.1 -uroot -pmysql -P 3306 ecard {} >> backup.sql
附:
MySQL的last_insert_id()
LAST_INSERT_ID() LAST_INSERT_ID(expr)
自动返回最后一个INSERT或UPDATE查询中AUTO_INCREMENT列设置的第一个发生的值
last_insert_id是针对connection的
假如使用单INSERT语句插入多个行,LAST_INSERT_ID()只返回插入的第一行产生的值