MySQL replace into Ó÷¨
ÔÚÏò±íÖвåÈëÊý¾ÝµÄʱºò£¬¾³£Óöµ½ÕâÑùµÄÇé¿ö£º1. Ê×ÏÈÅжÏÊý¾ÝÊÇ·ñ´æÔÚ£» 2. Èç¹û²»´æÔÚ£¬Ôò²åÈ룻3.Èç¹û´æÔÚ£¬Ôò¸üС£
ÔÚ SQL Server ÖпÉÒÔÕâÑù´¦Àí£º
if not exists (select 1 from t where id = 1) insert into t(id, update_time) values(1, getdate()) else update t set update_time = getdate() where id = 1
ÄÇô MySQL ÖÐÈçºÎʵÏÖÕâÑùµÄÂß¼ÄØ£¿±ð׿±£¡MySQL ÖÐÓиü¼òµ¥µÄ·½·¨£º replace into
replace into t(id, update_time) values(1, now());
»ò
replace into t(id, update_time) select 1, now();
replace into ¸ú insert ¹¦ÄÜÀàËÆ£¬²»Í¬µãÔÚÓÚ£ºreplace into Ê×Ïȳ¢ÊÔ²åÈëÊý¾Ýµ½±íÖУ¬ 1. Èç¹û·¢ÏÖ±íÖÐÒѾÓдËÐÐÊý¾Ý£¨¸ù¾ÝÖ÷¼ü»òÕßΨһË÷ÒýÅжϣ©ÔòÏÈɾ³ý´ËÐÐÊý¾Ý£¬È»ºó²åÈëеÄÊý¾Ý¡£ 2. ·ñÔò£¬Ö±½Ó²åÈëÐÂÊý¾Ý¡£
ҪעÒâµÄÊÇ£º²åÈëÊý¾ÝµÄ±í±ØÐëÓÐÖ÷¼ü»òÕßÊÇΨһË÷Òý£¡·ñÔòµÄ»°£¬replace into »áÖ±½Ó²åÈëÊý¾Ý£¬Õ⽫µ¼Ö±íÖгöÏÖÖظ´µÄÊý¾Ý¡£
MySQL replace into ÓÐÈýÖÖÐÎʽ£º
1. replace into tbl_name(col_name, ...) values(...) 2. replace into tbl_name(col_name, ...) select ... 3. replace into tbl_name set col_name=value, ...
Ç°Á½ÖÖÐÎʽÓõĶàЩ¡£ÆäÖÐ “into” ¹Ø¼ü×Ö¿ÉÒÔÊ¡ÂÔ£¬²»¹ý×îºÃ¼ÓÉÏ “into”£¬ÕâÑùÒâ˼¸ü¼ÓÖ±¹Û¡£ÁíÍ⣬¶ÔÓÚÄÇЩûÓиøÓèÖµµÄÁУ¬MySQL ½«×Ô¶¯ÎªÕâЩÁи³ÉÏĬÈÏÖµ¡£
Ïà¹ØÎĵµ£º
µÚÒ»ÖÖ:²éSlow queryµÄSQLÓï·¨:
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 2 (³¬¹ý2ÃëµÄSQLÓï·¨¼Ç¼ÆðÀ´,Éè¶ÌÒ»µãÀ´¼Ç¼³ý´íÒ²ÊÇÒ»ÖÖ·½·¨.)
µÚ¶þÖÖ:ÉèMySQL ReplicationÓÃbinlog:
log_bin = /var/log/mysql/mysql-bin.log (´ËµµÒªÓÃmysqlbinlog½âÀ´¿´£¬
mysqlbinl ......
Éý¼¶mysqlÊý¾Ý¿âµÄ·½·¨£º
1. ÏÂÔØ°²×°½éÖÊmysql-essential-5.1.46-win32.msi
¿ÉÒÔµ½¹ÙÍøhttp://www.mysql.com/click.php?e=35166»òÆäËûÍøվȥÏÂÔØ£»
2. ±¸·ÝmysqlµÄÊý¾Ý£»
ÔËÐÐcmd´ò¿ªÃüÁîÌáʾ·û£¬½øÈëµ½mysqlÈí¼þµÄ ......
»ùÓÚMySQLºÍInfobrightµÄÊý¾Ý²Ö¿â¼¼Êõ
Êý¾Ý²Ö¿â/·ÖÎö/ÉÌÎñÖÇÄÜ( BI )ÁìÓòÕýÔÚ·ÉËÙ·¢Õ¹¡£ÔÚ¼¤Áҵľ¼Ã¾ºÕùÖÐËùÓÐÐÐÒµºÍÖÇÄÜÆóÒµÐèÒªÀûÓÃÆäÄÚ²¿µÄÊý¾ÝÀ´×ö³öÖØÒªµÄÉÌÒµ¾ö²ß£¬°üÀ¨Õ½ÊõºÍÕ½ÂÔÁ½·½Ã棬ÒÔ±£³ÖÐÐÒµµÄÁìÏȵØλ¡£
Êý¾Ý²Ö¿â(Èç¶ÔMySQLµÄÒ»´ÎÖØ´óÉç»áºÍ¿Í»§µ÷²é)Ä¿Ç°ÊÇMySQLµÄµÚÎåÖÖ×î³£¼ûµÄÓ¦Óá£ÏÖÔÚÓÃÓÚMySQLÊý¾Ý ......
¸ømysql¿ªÒ»¸ö¿ÉÒÔÔ¶³Ì·ÃÎʵÄÓû§ÃüÁîÈçÏÂ:
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
"*.*" ±íʾÊý¾Ý¿âÖÐËùÓеıí,Ò²¿ÉÒÔ»»³ÉÖ¸¶¨µÄ±íÈçtest.*
"myuser" ±íʾµÄÊÇ·ÃÎʵÄÓû§Ãû;
"%" ±íʾËùÓеÄÖ÷»ú¼´ÈκεÄÖ÷»ú¶¼¿ÉÒÔͨ¹ýÕâ¸öÓû§Ãû·ÃÎÊÎÒµÄÊý¾Ý¿â,Ò²¿ÉÒԸóÉÌض¨µ ......