¸ßÐÔÄÜMYSQL¶ÁÊé±Ê¼Ç£ºMYSQL×¼±¸Óï¾ä
MYSQL4.1¼°¸ü¸ß°æ±¾Ö§³Ö·þÎñÆ÷¶Ë×¼±¸Óï¾ä(Prepared Statements), ËüʹÓÃÔöÇ¿µÄ¶þ½øÖÆ¿Í»§¶Ë/·þÎñÆ÷ÐÒéÔÚ¿Í»§¶ËºÍ·þÎñÆ÷Ö®¼ä¸ßЧµÄ·¢ËÍÊý¾Ý£¬¿ÉÒÔͨ¹ýÖ§³ÖÕâÖÖÐÐÐÒéµÄ±à³Ì¿âÀ´·ÃÎÊ×¼±¸Óï¾ä£¬ÁÐÈëMYSQL CAPI,MYSQL Connector/JºÍMYSQL Connector/NET ΪJAVAºÍ.NETÌṩÁËͬÑùµÄ·ÃÎʽӿڡ£ËüÒ²ÓÐSQLÓïÑԵķÃÎʽӿڡ£
´´½¨×¼±¸Óï¾äʱ£¬¿Í»§¶Ë¿â»áÏñ·þÎñÆ÷·¢ËÍÒ»¸öʵ¼Ê²éѯµÄÔÐÍ£¬È»ºó·þÎñÆ÷¶Ô¸ÃÔÐͽøÐнâÎöºÍ´¦Àí£¬½«²¿·ÖÓÅ»¯¹ýµÄÔÐͱ£´æÆðÀ´£¬²¢ÇÒ¸ø¿Í»§¶Ë·µ»ØÒ»¸ö״̬¾ä±ú(State Handle) ¿Í»§¶Ë¿ÉÒÔͨ¹ý¶¨Òå״̬¾ä±úÖظ´µÄÖ´Ðвéѯ¡£
¿ÉÒÔ°´ÏÂÃæµÄ·½Ê½×¼±¸²éѯ£º
INSERT INTO table(col1,col2,col3) VALUES(?,?,?);
MYSQLΪ׼±¸Óï¾äÌṩÁËSQLÓïÑÔ½Ó¿Ú¡£ÀýÈ磺
SET @sql = 'SELECT col1,col2,col3' from table where col1 = ?';
PREPARE stmt_fetch_actor from @sql;
SET @name = 'test';
EXECUTE smtm_fetch_actor USING @name;
DEALLOCATE PREPARE smtm_fetch_actor;
ÔÚMYSQL 5.0ÖпÉÒÔÔÚ´æ´¢¹ý³ÌÖÐʹÓÃ×¼±¸Óï¾ä¡£
×¼±¸Óï¾ä»á±È¶à´ÎÖ´ÐвéѯЧÂʸߺܶ࣬¾ßÌåÔÒòÈçÏ£º
1.·þÎñÆ÷Ö»ÐèÒª½âÎöÒ»´Î²éѯ£¬Õâ½ÚÔ¼Á˽âÎöºÍÆäËû¿ªÏú
2.ÒòΪ·þÎñÆ÷»º´æÁËÒ»²¿·ÖÖ´Ðмƻ®£¬ËùÒÔËüÖ»ÐèÒªÖ´ÐÐijЩÓÅ»¯²½ÖèÒ»´Î¡£
ͨ¹ý¶þ½øÖÆ·¢ËͲÎÊý±Èͨ¹ýASCIIÂëÒª¿ìµÄ¶à£¬±ÈÈ磬ͨ¹ý¶þ½øÖÆ·¢ËÍDATEÀàÐ͵IJÎÊýÖ»ÐèÒª3×Ö½Ú£¬µ«Í¨¹ýASCIIÂë·¢ËÍÐèÒª10¸ö×Ö½Ú¡£½â¾öµÄЧ¹û¶ÔÓÚBLOBºÍTEXTÀàÐÍ×îΪÏÔÖø¡£ÒòΪËûÃÇ¿ÉÒԳɿéµÄ·¢ËÍ¡£¶ø²»ÊÇÒ»¸ö¸öµÄ·¢ËÍ¡£¶þ½øÖÆÐÒéÒ²°ï¿Í»§¶Ë½ÚÔ¼ÁËÄڴ棬ͬʱ¼õÉÙÁËÍøÂ翪ÏúºÍÊý¾Ý´Ó±¾ÉíµÄÀàÐÍת»»Îª·Ç¶þ½øÖÆÐÒéµÄ¿ªÏú¡£
3.Õû¸ö²éѯ²»»á±»·¢Ë͵½·þÎñÆ÷¡£Ö»ÓвÎÊý²Å»á±»·¢ËÍ£¬¼õÉÙÁËÍøÂçÁ÷Á¿¡£
4.MYSQLÖ±½Ó°É²ÎÊý±£´æÔÚ·þÎñÆ÷µÄ»º³åÇøÄÚ£¬²»ÐèÒªÔÚÄÚ´æÖе½´¦¿½±´Êý¾Ý¡£
5.×¼±¸Óï¾ä¶ÔÓÚ°²È«ÐÔÒ²Óкô¦£¬Ëü²»ÐèÒªÔÚÓ¦ÓóÌÐòÖжÔÖµ½øÐÐתÒƺͼÓÒýºÅ¡£Õâ¸ü¼Ó·½±ã£¬²¢ÇÒ¼õÉÙÁËSQLÔâÊÜ×¢Èë¹¥»÷ºÍÆäËû¹¥»÷µÄ¿ÉÄÜ(ÓÀÔ¶Ò²²»ÄÜÐÅÈÎÓû§µÄÊäÈ룬¼´Ê¹Ê¹ÓÃ×¼±¸Óï¾äÒ²²»ÄÜ)
Ö»ÓÐ×¼±¸Óï¾äÄÜʹÓöþ½øÖÆÐÒ飬ʹÓÃÆÕͨµÄMSYQL_QUERY()º¯ÊýÌá½»²éѯ²»»áʹÓöþ½øÖÆÐÒ飬
×¼±¸Óï¾äµÄ¾ÖÏÞ£º
1.×¼±¸Óï¾äÖ»Õë¶ÔÒ»¸öÁ¬½Ó£¬ËùÒÔÁíÍâµÄÁ¬½Ó²»ÄÜʹÓÃͬÑùµÄ¾ä±ú£¬´¦ÓÚͬÑùµÄÔÒò£¬Ò»¸öÏȶϿªÔÙÖØÐÂÁ¬½ÓµÄ¿Í»§¶Ë»á¶ªÊ§¾ä±ú(Á¬½Ó³Ø»î³ÖÐøÁ¬½Ó»á¼õÇáÕâ¸öÎÊÌâ)
2.×¼±¸Óï¾ä²»ÄÜʹÓÃMYSQL5.0ÒÔÇ°µÄ°æ±¾»º´æ
3.ʹÓÃ×¼±¸Óï¾ä²¢²»×ÜÊǸßЧ£¬Èç¹ûֻʹÓÃÒ»´Î×¼±¸Ó
Ïà¹ØÎĵµ£º
#!/bin/bash
#ɾ³ý100¸öÊý¾Ý¿âÖеÄ1000¸ö±íµÄ¹ýÆÚÊý¾Ý
DBHOST="127.0.0.1"
DBPWD="pwd"
DBUSER="root"
MYSQLBIN="/usr/local/mysql/bin/mysql"
for((dbindex = 0;dbindex < 100;dbindex++))
do
for((tabindex = 0;tabindex < 10;tabindex++))
do
if [&n ......
1.²é¿´µµ°¸
mysql> show binary logs;
+----------------+-----------+
| Log_name | File_size |
+----------------+-----------+
| ablelee.000001 | 150462942 |
| ablelee.000002 | 125 |
| ablelee.000003 | 106 |
+----------------+-----------+
2.ɾ³ýbin-log(ɾ³ýablelee.000003֮ǰµÄ¶øûÓаüº¬ablel ......
Õ⼸ÌìѧϰÁË´¥·¢Æ÷µÄÓ÷¨£¬¾õµÃ´¥·¢Æ÷ºÜºÃÓð¡¡£
´¥·¢Æ÷µÄ»ù±¾Óï·¨£º
CREATE TRIGGER <´¥·¢Æ÷Ãû><--
{BEFORE | AFTER}
{ INSERT | UPDATE | DELETE }
ON <±íÃû³Æ>
FOR EACH ROW
<´¥·¢Æ÷SQLÓï¾ä>
¹æÔò£º
1.´¥·¢Æ÷±ØÐëÓÐÃû×Ö£¬×î¶à64¸ö×Ö·û£¬¿ÉÄܺóÃæ»á¸½Óзָô·û.ËüºÍMySQLÖÐÆäËû¶ÔÏóµÄÃüÃû· ......
1¡¢±à¼MySQL(ºÍPHP´îÅäÖ®×î¼Ñ×éºÏ)ÅäÖÃÎļþ£º
windows»·¾³ÖУº%MySQL(ºÍPHP´îÅäÖ®×î¼Ñ×éºÏ)_installdir%\my.ini¡¡//Ò»°ãÔÚMySQL(ºÍPHP´îÅäÖ®×î¼Ñ×éºÏ)°²×°Ä¿Â¼ÏÂÓÐmy.ini¼´MySQL(ºÍPHP´îÅäÖ®×î¼Ñ×éºÏ)µÄÅäÖÃÎļþ¡£
linux»·¾³ÖУº/etc/my.cnf
ÔÚ[MySQL(ºÍPHP´îÅäÖ®×î¼Ñ×éºÏ)d]ÅäÖöÎÌí¼ÓÈçÏÂÒ»ÐУº
skip-grant-tables
......