mysqlÖд¥·¢Æ÷µÄÓ¦ÓÃ
Õ⼸ÌìѧϰÁË´¥·¢Æ÷µÄÓ÷¨£¬¾õµÃ´¥·¢Æ÷ºÜºÃÓð¡¡£
´¥·¢Æ÷µÄ»ù±¾Óï·¨£º
CREATE TRIGGER <´¥·¢Æ÷Ãû><--
{BEFORE | AFTER}
{ INSERT | UPDATE | DELETE }
ON <±íÃû³Æ>
FOR EACH ROW
<´¥·¢Æ÷SQLÓï¾ä>
¹æÔò£º
1.´¥·¢Æ÷±ØÐëÓÐÃû×Ö£¬×î¶à64¸ö×Ö·û£¬¿ÉÄܺóÃæ»á¸½Óзָô·û.ËüºÍMySQLÖÐÆäËû¶ÔÏóµÄÃüÃû·½Ê½»ù±¾ÏàÏó
2.ÎÒÃDz»ÄܸøͬһÕűíµÄͬһ¸öʼþ°²ÅÅÁ½¸ö´¥·¢Æ÷
3.FOR EACH ROW×Ó¾ä֪ͨ´¥·¢Æ÷ÿ¸ôÒ»ÐÐÖ´ÐÐÒ»´Î¶¯×÷£¬¶ø²»ÊǶÔÕû¸ö±íÖ´ÐÐÒ»´Î¡£
4.Äã±ØÐëÓµÓÐÏ൱´óµÄȨÏÞ²ÅÄÜ´´½¨´¥·¢Æ÷£¨CREATE TRIGGER£©¡£
5.´¥·¢Æ÷°üº¬ËùÒª´¥·¢µÄSQLÓï¾ä£ºÕâÀïµÄÓï¾ä¿ÉÒÔÊÇÈκκϷ¨µÄÓï¾ä£¬°üÀ¨¸´ºÏÓï¾ä£¬µ«ÊÇÕâÀïµÄÓï¾äÊܵÄÏÞÖƺͺ¯ÊýµÄÒ»Ñù:
ALTER 'CACHE INDEX' CALL COMMIT CREATE DELETE
DROP 'FLUSH PRIVILEGES' GRANT INSERT KILL
LOCK OPTIMIZE REPAIR REPLACE REVOKE
ROLLBACK SAVEPOINT 'SELECT from table'
'SET system variable' 'SET TRANSACTION'
SHOW 'START TRANSACTION' TRUNCATE UPDATE
6.¿ÉÒÔʹÓÃNEWÓëOLD¹Ø¼ü×ÖÀ´·ÃÎʸüÐÂÇ°ºóµÄÊý¾Ý
ÀýÈ磺
create trigger t3
after
delete on article for each row
insert into xy_user(name,email,hobby)values('admin','admin@163.com','zuqiu');
Ïà¹ØÎĵµ£º
ÏÔʾ¡¢ÉèÖÃ×Ô¶¯Ìá½» show variable like 'autocommit' set autocommit=1 or 0
ÉèÖÃÈÕÖ¾£º
ÔÚ/etc/mysql/my.cnfÖÐÉèÖÃÈçÏ¿ÉÔÙslow.logÖÐÊä³öÔËÐÐʱ¼ä³¬¹ýÒ»ÃëµÄsqlÓï¾ä
[mysqld]
log-slow-queries = /tmp/slow.log
long_query_time = 1
ÉèÖÃÈÕÖ¾Êä³öÔËÐг¬¹ý1ÃëµÄsqlÓï¾ä set global long_query_ti ......
1£ºMysql ÃüÁî²»¿ÉÒÔÖ´ÐÐ
ÔÒò £ººÇºÇ ±ÈÈç show databases µÄÃüÁî £¬Ö´ÐÐÍêÖ®ºó ɶҲûÓÐ £¬×Ðϸ ÕÒÁËÔÒò £¬Oh my god ÉÙÁË ·ÖºÅ¡£
Ӧд³É£ºshow databases;
2£ºÃüÁîÐÐÖÐÎÄÂÒÂëÎÊÌâ
ÏÖÏó£ºmysqlµÄĬÈϱàÂëÉèÖÃΪutf-8£¬Ò³ÃæÒÔutf-8µÄ±àÂ뷽ʽдÈëµ½Êý¾Ý¿â¡£Óù¤¾ß²é¿´Ò»ÇÐÕý³££¬µ«´ÓmysqlµÄÃüÁîÐжÁÊý¾Ý³öÀ´× ......
CREATE PROCEDURE pro_page(
in _sql varchar(1000),
in _order varchar(1000),
in _pagecurrent int,
in _pagesize int
)
BEGIN
if _pagesize<=1 then
set _pagesize=20;
end if;
if _pagecurrent < 1 then
set _pagecurrent = 1;
&n ......
1¡¢´ò¿ªÎı¾±à¼my.cnf
sudo gedit /etc/mysql/my.cnf
ÔÚ[client]
½Úµã£¬Ìí¼Ó
default-character-set=utf8 (¿Í»§¶ËȱʡÒÔutf8´æ´¢)
ÔÚ[mysqld]
½Úµã£¬Ìí¼Ó
default-character-set=utf8 (Êý¾Ý¿âȱʡÒÔutf8´æ´¢)
init_connect='SET NAMES utf8'
£¨É趨Á¬½ÓmysqlÊý¾Ý¿âʱʹÓÃutf8±àÂ룬ÒÔÈÃmysqlÊý¾Ý¿âΪutf8 ......
USE dxdb;
DELIMITER //
#»ñÈ¡Á÷Ë®ºÅ
DROP PROCEDURE IF EXISTS get_sid;
CREATE PROCEDURE get_sid(para_domain VARCHAR(20), out para_sid BIGINT UNSIGNED)
BEGIN
START TRANSACTION;
UPDATE t_sid SET sID=sID+1 WHERE cDomain=para_domain;
SELECT sID INTO para_sid from t_sid WHERE cDomain=para_domain;
......