MySQLʹÓô¥·¢³ÌÐò
´¥·¢³ÌÐòÊÇÓë±íÓйصÄÃüÃûÊý¾Ý¿â¶ÔÏ󣬵±±íÉϳöÏÖÌض¨Ê¼þʱ£¬½«¼¤»î¸Ã¶ÔÏó¡£ÔÚijЩ´¥·¢³ÌÐòµÄÓ÷¨ÖУ¬¿ÉÓÃÓÚ¼ì²é²åÈëµ½±íÖеÄÖµ£¬»ò¶Ô¸üÐÂÉæ¼°µÄÖµ½øÐмÆËã¡£
´¥·¢³ÌÐòÓë±íÏà¹Ø£¬µ±¶Ô±íÖ´ÐÐINSERT¡¢DELETE»òUPDATEÓï¾äʱ£¬½«¼¤»î´¥·¢³ÌÐò¡£¿ÉÒÔ½«´¥·¢³ÌÐòÉèÖÃΪÔÚÖ´ÐÐÓï¾ä֮ǰ»òÖ®ºó¼¤»î¡£ÀýÈ磬¿ÉÒÔÔÚ´Ó±íÖÐɾ³ýÿһÐÐ֮ǰ£¬»òÔÚ¸üÐÂÁËÿһÐк󼤻·¢³ÌÐò¡£
ÒªÏë´´½¨´¥·¢³ÌÐò»òÉáÆú´¥·¢³ÌÐò£¬¿ÉʹÓÃCREATE TRIGGER»òDROP TRIGGERÓï¾ä
ÏÂÃæ¸ø³öÁË1¸ö¼òµ¥µÄʾÀý£¬ÔÚ¸ÃʾÀýÖУ¬Õë¶ÔINSERTÓï¾ä£¬½«´¥·¢³ÌÐòºÍ±í¹ØÁªÁËÆðÀ´¡£Æä×÷ÓÃÏ൱ÓÚÀÛ¼ÓÆ÷£¬Äܹ»½«²åÈë±íÖÐijһÁеÄÖµ¼ÓÆðÀ´¡£
ÔÚÏÂÃæµÄÓï¾äÖУ¬´´½¨ÁË1¸ö±í£¬²¢Îª±í´´½¨ÁË1¸ö´¥·¢³ÌÐò£º
mysql> CREATE TABLE account (acct_num INT, amount DECIMAL(10,2));
mysql> CREATE TRIGGER ins_sum BEFORE INSERT ON account
-> FOR EACH ROW SET @sum = @sum + NEW.amount;
CREATE TRIGGERÓï¾ä´´½¨ÁËÓëÕË»§±íÏà¹ØµÄ¡¢ÃûΪins_sumµÄ´¥·¢³ÌÐò¡£Ëü»¹°üÀ¨Ò»Ð©×Ӿ䣬ÕâЩ×Ó¾äÖ¸¶¨ÁË´¥·¢³ÌÐò¼¤»îʱ¼ä¡¢´¥·¢³ÌÐòʼþ¡¢ÒÔ¼°¼¤»î´¥·¢³ÌÐòʱ×÷Щʲô£º
· ¹Ø¼ü×ÖBEFOREÖ¸Ã÷ÁË´¥·¢³ÌÐòµÄ¶¯×÷ʱ¼ä¡£ÔÚ±¾ÀýÖУ¬Ó¦ÔÚ½«Ã¿Ò»ÐвåÈë±í֮ǰ¼¤»î´¥·¢³ÌÐò¡£ÕâÀàÔÊÐíµÄÆäËû¹Ø¼ü×ÖÊÇAFTER¡£
· ¹Ø¼ü×ÖINSERTÖ¸Ã÷Á˼¤»î´¥·¢³ÌÐòµÄʼþ¡£ÔÚ±¾ÀýÖУ¬INSERTÓï¾ä½«µ¼Ö´¥·¢³ÌÐòµÄ¼¤»î¡£ÄãÒ²¿ÉÒÔΪDELETEºÍUPDATEÓï¾ä´´½¨´¥·¢³ÌÐò¡£
· ¸úÔÚFOR EACH ROWºóÃæµÄÓï¾ä¶¨ÒåÁËÿ´Î¼¤»î´¥·¢³ÌÐòʱ½«Ö´ÐеijÌÐò£¬¶ÔÓÚÊÜ´¥·¢Óï¾äÓ°ÏìµÄÿһÐÐÖ´ÐÐÒ»´Î¡£ÔÚ±¾ÀýÖУ¬´¥·¢µÄÓï¾äÊǼòµ¥µÄSETÓï¾ä£¬¸ºÔ𽫲åÈëamountÁеÄÖµ¼ÓÆðÀ´¡£¸ÃÓï¾ä½«ÁÐÒýÓÃΪNEW.amount£¬Òâ˼ÊÇ“½«Òª²åÈëµ½ÐÂÐеÄamountÁеÄÖµ”¡£
ÒªÏëʹÓô¥·¢³ÌÐò£¬½«ÀÛ¼ÓÆ÷±äÁ¿ÉèÖÃΪ0£¬Ö´ÐÐINSERTÓï¾ä£¬È»ºó²é¿´±äÁ¿µÄÖµ£º
mysql> SET @sum = 0;
mysql> INSERT INTO account VALUES(137,14.98),(141,1937.50),(97,-100.00);
mysql> SELECT @sum AS 'Total amount inserted';
+-----------------------+
| Total amount inserted |
+-----------------------+
| 1852.48  
Ïà¹ØÎĵµ£º
Ê×ÏÈ·ÅÖúÃjdbcÇý¶¯³ÌÐò£¬ÔÚ java\jre6\lib\ext\Ï£¬java\jdk1.6\jre\libµÈµØ·½¶¼·ÅÆðÀ´£¬ÒòΪ²»È·¶¨ÔÚÄÄÀïÓÐÓ÷··
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost/DATABASENAME?user=USERNAME&password=PASSWORD&useUnicode=tru ......
¹Ø¼ü×Ö: mysql6 mysql6ÏÂÔØ
×÷ΪһÃû¿ª·¢ÈËÔ±,ÎÒ¶ÔÂÌɫСÈí¼þÇéÓжÀÖÓ,ÒòΪÓÃÆðÀ´·½±ã¿ì½ÝÂï,±ãÓÚЯ´ø,Ò×ÓÚÔÚÑÝʾϵͳÖÐʹÓÃ,¿ª·¢Ê±¿ÉÁ¢¼´½øÈë״̬. £¨ÔÚ¸½¼þÖУ©
ÒÔÏÂÊÇÏêϸ˵Ã÷:
MySQL 6 ÂÌÉ«¾«¼ò°æ(BAT°æ±¾)
MySQL 6 Ö§³ÖÍâ¼ü,ÊÓͼ´æ´¢¹ý³Ì,ÊÂÎñµÈ¹¦ÄÜ(ÂÌÉ«¾« ......
ÓÉÓÚ×î½üÒ»Ö±ÔÚÁ˽âmysql¡£¸÷ÖÖ±íÀàÐ͵ÄÊý¾Ý´æ´¢ÒÔ¼°Ïà¹ØÏÞÖƾÍÊDZØÐëÁ˽âµÄ·½ÃæÁË¡£
×Ô¼ºµÄ·þÎñÆ÷»·¾³£ºOS Cent OS ext3£¬memory 4G£¬ disk 2T block size 4K¡£
¾µ÷²é£¬linuxÏÂÎļþ×î´óÊÇ´æÔÚÏÞÖƵġ£È¥googleÉÏËÑÁËËÑ£¬´ó¼Ò˵·¨²»Ò»£¬×îÖÕ×Ô¼º»¹ÊÇÕÒµ½±È½Ï¹Ù·½µÄ˵¡£Ïê¼ûhttp://en.wikipedia.org/wiki/Ext3 ËùÒÔ× ......
mysqlÎļþµ¼ÈëÂÒÂëÎÊÌâµÄ½â¾ö£º
1 ÃüÁî²ì¿´×Ö·ûÉèÖá£
mysql> show variables like "%char%";
2 ½«²»ÊÇutf-8µÄ¶¼¸Ä³Éutf8¡£Ö»ÓÐfilesystem²»±ä;
| Variable_name | Value
&nb ......
mysql Êý¾Ý¿âĬÈϵÄÁ¬½ÓÖ»ÄÜÔÚ±¾»úÁ¬½Ó£¬Ô¶³ÌÁ¬½Ó±ØÐëÊÚȨ¡£
´úÂë: È«Ñ¡
¡¡GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'IDENTIFIED
BY 'mypassword' WITH GRANT
OPTION;Èç¹ûÄãÏëÔÊÐíÓû§myuser´ÓipΪ192.168.1.6µÄÖ÷»úÁ¬½Óµ½mysql·þÎñÆ÷£¬²¢Ê¹ÓÃ
mypassword×÷ΪÃÜÂë
´úÂë: GRANT ALL PR ......