ÅäÖÃMySQLÖ÷´Ó¸´ÖÆ(Replication)
MySQLÖ§³Öµ¥Ïò¡¢Òì²½¸´ÖÆ£¬¸´Öƹý³ÌÖÐÒ»¸ö·þÎñÆ÷³äµ±Ö÷·þÎñÆ÷£¬¶øÒ»¸ö»ò¶à¸öÆäËü·þÎñÆ÷³äµ±´Ó·þÎñÆ÷¡£Ö÷·þÎñÆ÷½«¸üÐÂдÈë¶þ½øÖÆÈÕÖ¾Îļþ£¬²¢Î¬»¤ÈÕÖ¾ÎļþµÄÒ»¸öË÷ÒýÒÔ¸ú×ÙÈÕ־ѻ·¡£µ±Ò»¸ö´Ó·þÎñÆ÷Á¬½Óµ½Ö÷·þÎñÆ÷ʱ£¬Ëü֪ͨÖ÷·þÎñÆ÷´Ó·þÎñÆ÷ÔÚÈÕÖ¾ÖжÁÈ¡µÄ×îºóÒ»´Î³É¹¦¸üеÄλÖᣴӷþÎñÆ÷½ÓÊÕ´ÓÄÇʱÆð·¢ÉúµÄÈκθüУ¬È»ºó·âËø²¢µÈ´ýÖ÷·þÎñÆ÷֪ͨÏÂÒ»´Î¸üС£
ΪʲôʹÓÃÖ÷´Ó¸´ÖÆ£¿
1¡¢Ö÷·þÎñÆ÷/´Ó·þÎñÆ÷ÉèÖÃÔö¼ÓÁ˽¡×³ÐÔ¡£Ö÷·þÎñÆ÷³öÏÖÎÊÌâʱ£¬Äã¿ÉÒÔÇл»µ½´Ó·þÎñÆ÷×÷Ϊ±¸·Ý¡£
2¡¢Í¨¹ýÔÚÖ÷·þÎñÆ÷ºÍ´Ó·þÎñÆ÷Ö®¼äÇзִ¦Àí¿Í»§²éѯµÄ¸ººÉ£¬¿ÉÒԵõ½¸üºÃµÄ¿Í»§ÏìӦʱ¼ä¡£µ«ÊDz»ÒªÍ¬Ê±ÔÚÖ÷´Ó·þÎñÆ÷ÉϽøÐиüУ¬ÕâÑù¿ÉÄÜÒýÆð³åÍ»¡£
3¡¢Ê¹Óø´ÖƵÄÁíÒ»¸öºÃ´¦ÊÇ¿ÉÒÔʹÓÃÒ»¸ö´Ó·þÎñÆ÷Ö´Ðб¸·Ý£¬¶ø²»»á¸ÉÈÅÖ÷·þÎñÆ÷¡£ÔÚ±¸·Ý¹ý³ÌÖÐÖ÷·þÎñÆ÷¿ÉÒÔ¼ÌÐø´¦Àí¸üС£
MySQLʹÓÃ3¸öÏß³ÌÀ´Ö´Ðи´Öƹ¦ÄÜ(ÆäÖÐ1¸öÔÚÖ÷·þÎñÆ÷ÉÏ£¬ÁíÁ½¸öÔÚ´Ó·þÎñÆ÷ÉÏ¡£µ±·¢³öSTART SLAVEʱ£¬´Ó·þÎñÆ÷´´½¨Ò»¸öI/OỊ̈߳¬ÒÔÁ¬½ÓÖ÷·þÎñÆ÷²¢ÈÃÖ÷·þÎñÆ÷·¢ËͶþ½øÖÆÈÕÖ¾¡£Ö÷·þÎñÆ÷´´½¨Ò»¸öÏ߳̽«¶þ½øÖÆÈÕÖ¾ÖеÄÄÚÈÝ·¢Ë͵½´Ó·þÎñÆ÷¡£´Ó·þÎñÆ÷I/OÏ̶߳ÁÈ¡Ö÷·þÎñÆ÷Binlog DumpÏ̷߳¢Ë͵ÄÄÚÈݲ¢½«¸ÃÊý¾Ý¿½±´µ½´Ó·þÎñÆ÷Êý¾ÝĿ¼Öеı¾µØÎļþÖУ¬¼´ÖмÌÈÕÖ¾¡£µÚ3¸öÏß³ÌÊÇSQLỊ̈߳¬´Ó·þÎñÆ÷ʹÓôËÏ̶߳ÁÈ¡ÖмÌÈÕÖ¾²¢Ö´ÐÐÈÕÖ¾Öаüº¬µÄ¸üС£SHOW PROCESSLISTÓï¾ä¿ÉÒÔ²éѯÔÚÖ÷·þÎñÆ÷ÉϺʹӷþÎñÆ÷ÉÏ·¢ÉúµÄ¹ØÓÚ¸´ÖƵÄÐÅÏ¢¡£
ĬÈÏÖмÌÈÕ־ʹÓÃhost_name-relay-bin.nnnnnnÐÎʽµÄÎļþÃû£¬ÆäÖÐhost_nameÊÇ´Ó·þÎñÆ÷Ö÷»úÃû£¬nnnnnnÊÇÐòÁкš£ÓÃÁ¬ÐøÐòÁкÅÀ´´´½¨Á¬ÐøÖмÌÈÕÖ¾Îļþ£¬´Ó000001¿ªÊ¼¡£´Ó·þÎñÆ÷¸ú×ÙÖмÌÈÕÖ¾Ë÷ÒýÎļþÀ´Ê¶±ðÄ¿Ç°ÕýʹÓõÄÖмÌÈÕÖ¾¡£Ä¬ÈÏÖмÌÈÕÖ¾Ë÷ÒýÎļþÃûΪhost_name-relay-bin.index¡£ÔÚĬÈÏÇé¿ö£¬ÕâЩÎļþÔÚ´Ó·þÎñÆ÷µÄÊý¾ÝĿ¼Öб»´´½¨¡£ÖмÌÈÕÖ¾Óë¶þ½øÖÆÈÕÖ¾µÄ¸ñʽÏàͬ£¬²¢ÇÒ¿ÉÒÔÓÃmysqlbinlog¶ÁÈ¡¡£µ±SQLÏß³ÌÖ´ÐÐÍêÖмÌÈÕÖ¾ÖеÄËùÓÐʼþºó£¬ÖмÌÈÕÖ¾½«»á±»×Ô¶¯É¾³ý¡£
´Ó·þÎñÆ÷ÔÚÊý¾ÝĿ¼ÖÐÁíÍâ´´½¨Á½¸ö״̬Îļþ--master.infoºÍrelay-log.info¡£×´Ì¬Îļþ±£´æÔÚÓ²ÅÌÉÏ£¬´Ó·þÎñÆ÷¹Ø±Õʱ²»»á¶ªÊ§¡£Ï´δӷþÎñÆ÷Æô¶¯Ê±£¬¶ÁÈ¡ÕâЩÎļþÒÔÈ·¶¨ËüÒѾ´ÓÖ÷·þÎñÆ÷¶ÁÈ¡Á˶àÉÙ¶þ½øÖÆÈÕÖ¾£¬ÒÔ¼°´¦Àí×Ô¼ºµÄÖмÌÈÕÖ¾µÄ³Ì¶È¡£
ÉèÖÃÖ÷´Ó¸´ÖÆ£º
1¡¢È·±£ÔÚÖ÷·þÎñÆ÷ºÍ´Ó·þÎñÆ÷ÉÏ°²×°µÄMySQL°æ±¾Ïàͬ£¬²¢ÇÒ×îºÃÊÇMySQLµÄ×îÐÂÎȶ¨°æ±¾¡£
2¡¢ÔÚÖ÷·þÎñ
Ïà¹ØÎĵµ£º
À´×Ô: http://www.phpv.net/html/1666.html
#BEGIN CONFIG INFO
#DESCR: 4GB RAM, ֻʹÓÃInnoDB, ACID, ÉÙÁ¿µÄÁ¬½Ó, ¶ÓÁиºÔØ´ó
#TYPE: SYSTEM
#END CONFIG INFO
#
# ´ËmysqlÅäÖÃÎļþÀý×ÓÕë¶Ô4GÄÚ´æ
# Ö÷ҪʹÓÃINNODB
#´¦Àí¸´ÔÓ¶ÓÁв¢ÇÒÁ¬½ÓÊýÁ¿½ÏÉÙµÄmysql·þÎñÆ÷
#
# ½«´ËÎļþ¸´ÖƵ½/etc/my.cnf ×÷Ϊȫ¾ÖÉèÖÃ, ......
×÷ÕߣºÀÏÍõ
MySQL5.X¶¼ÒѾ·¢²¼ºÃ¾ÃÁË£¬µ«ÊÇ»¹ÓкܶàÈËÈÏΪMySQLÊDz»Ö§³ÖÊÂÎñ´¦ÀíµÄ£¬Õâ²»µÃ²»¹ÖËûÃÇÊǹª¹ÑÎŵģ¬Æäʵ£¬Ö»ÒªÄãµÄMySQL°æ±¾Ö§³ÖBDB»òInnoDB±íÀàÐÍ£¬ÄÇôÄãµÄMySQL¾Í¾ßÓÐÊÂÎñ´¦ÀíµÄÄÜÁ¦¡£ÕâÀïÃ棬ÓÖÒÔInnoDB±íÀàÐÍÓõÄ×î¶à£¬ËäÈ»ºóÀ´·¢ÉúÁËÖîÈçOracleÊÕ¹ºInnoDBµÈÁîMySQL²»Ë¬µÄÊÂÇ飬µ«ÄÇЩÉÌÒµÉϵĶ·ÕùÓ ......
1.±àдshell½Å±¾
vi /data/www/project_name/bin/mysql_backup.sh
#!/bin/bash
#This is a ShellScript For Auto DB Backup
#Powered by liuzheng
#ϵͳ±äÁ¿¶¨Òå
DBName=test
DBUser=root
DBPasswd=123456
BackupPath=/tmp/mysql_backup/
NewFile="$BackupPath"db$(date +%y%m%d ......
MySQL½¨Á¢ÁÙʱ±íµÄÓï¾äÈçÏÂ:
CREATE TEMPORARY TABLE tmp (
article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
price DOUBLE(16,2) DEFAULT '0.00' NOT NULL);
--LOCK TABLES article read;
--ÏȲåÈëÊý¾Ýµ½ÁÙʱ±í
INSERT INTO tmp SELECT article, MAX(price) from shop GRO ......
ÊýÖµÀàÐÍ
¡¡¡¡MySQL
µÄÊýÖµÊý¾ÝÀàÐÍ¿ÉÒÔ´óÖ»®·ÖΪÁ½¸öÀà±ð£¬Ò»¸öÊÇÕûÊý£¬ÁíÒ»¸öÊǸ¡µãÊý»òСÊý¡£Ðí¶à²»Í¬µÄ×ÓÀàÐͶÔÕâЩÀà±ðÖеÄÿһ¸ö¶¼ÊÇ¿ÉÓõģ¬Ã¿¸ö×ÓÀàÐÍÖ§³Ö²»Í¬´óСµÄÊý¾Ý£¬²¢ÇÒ
MySQL ÔÊÐíÎÒÃÇÖ¸¶¨ÊýÖµ×Ö¶ÎÖеÄÖµÊÇ·ñÓÐÕý¸ºÖ®·Ö»òÕßÓÃÁãÌî²¹¡£
¡¡¡¡±íÁгöÁ˸÷ÖÖÊýÖµÀàÐÍÒÔ¼°ËüÃǵÄÔÊÐí·¶Î§ºÍÕ¼ÓõÄÄÚ´æ¿Õ¼ä¡ ......