ÈçºÎÉèÖÃMySQLͬ²½(Replication)
×÷ÕߣºÒ¶½ðÈÙ£¨Email: imysql#gmail.com£©£¬À´Ô´£ºhttp://iMySQL.cn£¬×ªÔØÇë×¢Ã÷×÷Õߺͳö´¦£¬²¢ÇÒ²»ÄÜÓÃÓÚÉÌÒµÓÃ;£¬Î¥Õ߱ؾ¿¡£
MySQLÌṩÁËÊý¾Ý¿âµÄͬ²½¹¦ÄÜ£¬Õâ¶ÔÎÒÃÇʵÏÖÊý¾Ý¿âµÄÈßÔÖ¡¢±¸·Ý¡¢»Ö¸´¡¢¸ºÔؾùºâµÈ¶¼ÊÇÓм«´ó°ïÖúµÄ¡£±¾ÎÄÃèÊöÁ˳£¼ûµÄͬ²½ÉèÖ÷½·¨¡£
Ò»¡¢×¼±¸·þÎñÆ÷
ÓÉÓÚMySQL²»Í¬°æ±¾Ö®¼äµÄ(¶þ½øÖÆÈÕÖ¾)binlog¸ñʽ¿ÉÄܻ᲻һÑù£¬Òò´Ë×îºÃµÄ´îÅä×éºÏÊÇMasterµÄMySQL°æ±¾ºÍSlaveµÄ°æ±¾Ïàͬ»òÕ߸üµÍ£¬MasterµÄ°æ±¾¿Ï¶¨²»ÄܸßÓÚSlave°æ±¾¡£
±¾ÎÄÖУ¬ÎÒÃǼÙÉèÖ÷·þÎñÆ÷(ÒÔϼò³ÆMaster)ºÍ´Ó·þÎñÆ÷(ÒÔϼò³ÆSlave)µÄ°æ±¾¶¼ÊÇ5.0.15£¬²Ù×÷ϵͳÊÇLinux Ubuntu 5.0.x¡£
¼ÙÉèͬ²½MasterµÄÖ÷»úÃûΪ£ºrep1£¬SlaveÖ÷»úÃûΪ£ºrep2£¬2¸öMySQLµÄbasedirĿ¼¶¼ÊÇ/usr/local/mysql£¬datadir¶¼ÊÇ£º/usr/local/MySQL/data¡£
¶þ¡¢ÉèÖÃͬ²½·þÎñÆ÷
1¡¢ÉèÖÃͬ²½Master
ÿ¸öͬ²½·þÎñÆ÷¶¼±ØÐëÉ趨һ¸öΨһµÄ±àºÅ£¬·ñÔòͬ²½¾Í²»ÄÜÕý³£ÔËÐÐÁË¡£½ÓÏÂÀ´¿ªÊ¼ÐÞ¸Ä my.cnf£¬Ôö¼ÓÒÔϼ¸ÐУº
server-id = 1
log-bin
set-variable=binlog-ignore-db=MySQL
È»ºóÔÚMasterÉÏÔö¼ÓÒ»¸öÕ˺ÅרÃÅÓÃÓÚͬ²½£¬ÈçÏ£º
MySQL>GRANT REPLICATION SLAVE ON *.* TO rep@rep2 IDENTIFIED BY 'rep';
Èç¹ûÏëÒªÔÚSlaveÉÏÓÐȨÏÞÖ´ÐÐ "LOAD TABLE from MASTER" »ò "LOAD DATA from MASTER" Óï¾äµÄ»°£¬±ØÐëÊÚÓèÈ«¾ÖµÄ FILE ºÍ SELECT ȨÏÞ£º
MySQL>GRANT FILE,SELECT,REPLICATION SLAVE ON *.* TO rep@rep2 IDENTIFIED BY 'rep';
µÚÈýÐбíʾ²»¼Ç¼Êý¾Ý¿âMySQLµÄ¸üÐÂÈÕÖ¾£¬Õâ¾Í±ÜÃâÁËMasterÉϵÄȨÏÞÉèÖõȱ»Í¬²½µ½SlaveÉÏ£¬Èç¹û¶ÔÕâ·½ÃæûÓÐÏÞÖÆ£¬¾Í¿ÉÒÔ²»ÉèÖÃÕâ¸ö²ÎÊý¡£
½ÓÏÂÀ´±¸·ÝMasterÉϵÄÊý¾Ý£¬Ê×ÏÈÖ´ÐÐÈçÏÂSQLÓï¾ä£º
MySQL>FLUSH TABLES WITH READ LOCK;
²»ÒªÍ˳öÕâ¸öÖնˣ¬·ñÔòÕâ¸öËø¾Í²»ÉúЧÁË£»½Ó×ŵ¼³öÊý¾Ý£¬¿ÉÒÔÖ±½Ó´ò°üѹËõÊý¾ÝÎļþ£¬Ò²¿ÉÒÔʹÓÃMySQLdump¹¤¾ßÀ´×ö£¬ÍƼöÇ°Õߵķ½·¨£¬ÕâÑù¸üΪ¿ì½Ý¼ò±ã¡£
root$cd /usr/local/MySQL
root$tar zcf data.tar.gz ./data (ÔÚÕâÀïÒ²¿ÉÄÜÊÇ "var" µÈÆäËüʵ¼Ê´æ·ÅÊý¾ÝÎļþµÄĿ¼£¬¸ù¾ÝʵÇé¶ø¶¨)
È»ºó½«ÕâЩÊý¾Ý¿½±´µ½Slave·þÎñÆ÷ÉÏ£¬½â¿ª£¬ÉèÖúÃÕýÈ·µÄȨÏÞ¼°ÊôÖ÷µÈ£»Ö®ºó£¬Ö´ÐÐ "UNLOCK TABLES" Óï¾äÀ´ÊÍ·ÅËø¡£
2¡¢ÉèÖÃSlave
ÐÞ¸Ämy.cnf£¬Ôö¼ÓÈçϼ¸ÐУº
server-id = 2
master-host = rep1 #Ö÷·þÎñÆ÷Ãû
master-user = rep #ͬ²½ÕË»§Ãû£¬Ä¬ÈÏÊÇtest
master-password = rep #ͬ²½ÕÊ»§ÃÜÂ룬ĬÈÏÊÇ¿Õ
master-
Ïà¹ØÎĵµ£º
°æȨÉùÃ÷£º¿ÉÒÔÈÎÒâתÔØ£¬×ªÔØʱÇëÎñ±ØÒÔ³¬Á´½ÓÐÎʽ±êÃ÷ÎÄÕÂÔʼ³ö´¦ºÍ×÷ÕßÐÅÏ¢¼°±¾ÉùÃ÷
http://www.5ilinux.com/lamp01.html
¹Ø¼ü×Ö£ºapache+mysql+php apache mysql php ÅäÖà lamp ·þÎñÆ÷ web
Linux+Apache+Mysql+PHPµäÐÍÅäÖÃ
µ÷ÊÔ»·¾³£ºRedhat9.0 Apache1.3.29 Mysql3.23.58 PHP4.3.4
LinuxϵͳµÄ°²×°ÎҾͲ»½²Á ......
¶ÔÓÚÕë¶Ô×Ö·û´®Î»ÖõIJÙ×÷£¬µÚÒ»¸öλÖñ»±ê¼ÇΪ1¡£
ASCII(str) ·µ»Ø×Ö·û´®strµÄ×î×óÃæ×Ö·ûµÄASCII´úÂëÖµ¡£Èç¹ûstrÊÇ¿Õ×Ö·û´®£¬·µ»Ø0¡£Èç¹ûstrÊÇNULL£¬·µ»ØNULL¡£
mysql> select ASCII('2');
-> 50
mysql> select ASCII(2);
-> 50
mysql> select ASCII('dx');
-> 100
Ò² ......
Õâ¶Îʱ¼ä±»Õâ¸öÀ§ÈÅÁ˺ܾã¬Í¨¹ýÐÞ¸ÄÅäÖÃÎļþ£¬ÖÕÓÚ°ÑÕâ¸öÎÊÌâ½â¾öÁË¡£
×Ô¼ºÔÚÍøÉÏÒ²ÕÒÁ˺ܶà¹ØÓÚ½â¾öÕâ¸öÎÊÌâµÄ·½·¨£¬µ«ÊǶ¼½²µÄ²»Ì«Çå³þ£¬ËùÒÔ½ñÌìÔÚÕâÖØÐÂ˵ÏÂÕâ¸öÎÊÌâ¡£
ÎҵĽâ¾ö·½·¨ÊÇͨ¹ýÐÞ¸ÄmysqlµÄÅäÖÃÎļþmy.ini£¬·½·¨ÈçÏ£º
ÔÚmy.iniÖпÉÒÔ·¢ÏÖÓÐÕâôһ¶Î´úÂ룺
[client]
port=3306
[mysql]
default ......
×î½üÔÚ×öPHPÓëÊý¾Ý¿â½»»¥µÄproject£¬¼±ÓÚÇó³É£¬Ä£·ÂÁËÏÂÀý×ӾͿªÊ¼¶¯ÊÖ£¬½á¹ûÎó°Ñmysql_fetch_arrayд³ÉÁËmysql_fetch_row,囧ÊÂÀ´ÁË£¬·¢ÏÖ·µ»ØµÄÊý×é¾ÓÈ»ÊÇindex=>valueµÄÐÎʽ£¬¶øÃ÷Ã÷¼ÇµÃÊÇfield name=>valueµÄ¹þ£¬²éÊÖ²á²ÅÃ÷°×¡£
1. mysql_fetch_arrayµÄº¯ÊýÔÐÍÊÇ
array mysql_fetch_array ( resour ......
MySQL±£Áô¹Ø¼ü×Ö
create table option (oid integer not null auto_increment, oname varchar(255), oinf varchar(255), ovotes integer, oimage varchar(255), ovideo varchar(255), oaudio varchar(255), octime varchar(255), ocuname varchar(255), omtime varchar(255), omuname varchar(255 ......