Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

MySQL Master/SlaveÊý¾Ý¿â¶Áд²Ù×÷Àà

Êý¾Ý¿â²Ù×÷ÀࣺDBCommon.class.php
//---------------------------------------------------------------------
// MySQL Master/SlaveÊý¾Ý¿â¶Áд²Ù×÷Àà
//
// ¿ª·¢×÷Õß: heiyeluren
// °æ±¾ÀúÊ·:
// 2006-09-20 »ù±¾µ¥Êý¾Ý¿â²Ù×÷¹¦ÄÜ, 25 ¸ö½Ó¿Ú
// 2007-07-30 Ö§³Öµ¥Master/¶àSlaveÊý¾Ý¿â²Ù×÷£¬29¸ö½Ó¿Ú
// 2008-09-07 ÐÞÕýÁËÉÏÒ»°æ±¾µÄ²¿·ÖBug
// 2009-11-17 ÔÚMaster/SlaveÀàµÄ»ù´¡ÉÏÔö¼ÓÁËÇ¿»¯µ¥Ö÷»ú²Ù×÷£¬
// Ôö¼ÓÁ˲¿·Ö¼ò½à²Ù×÷½Ó¿ÚºÍµ÷ÊÔ½Ó¿Ú£¬ÓÅ»¯Á˲¿·Ö´úÂ룬
// ±¾°æ±¾¹²42¸ö½Ó¿Ú
// Ó¦ÓÃÏîÄ¿: Y!NCP, Y!SNS, TM MiniSite//
// ¹¦ÄÜÃèÊö£º×Ô¶¯Ö§³ÖMaster/Slave ¶Á/д ·ÖÀë²Ù×÷£¬Ö§³Ö¶àSlaveÖ÷»ú
//
//-----------------------------------------------------------------------



/**
* ³£Á¿¶¨Òå
*/
define("_DB_INSERT", 1);
define("_DB_UPDATE", 2);


/**
* DB Common class
*
* ÃèÊö£ºÄܹ»·Ö±ð´¦Àíһ̨Masterд²Ù×÷£¬¶ą̀Slave¶Á²Ù×÷
*/
class DBCommon
{
/**
* Êý¾Ý¿âÅäÖÃÐÅÏ¢
*/
var $wdbConf = array();
var $rdbConf = array();
/**
* MasterÊý¾Ý¿âÁ¬½Ó
*/
var $wdbConn = null;
/**
* SlaveÊý¾Ý¿âÁ¬½Ó
*/
var $rdbConn = array();
/**
* µ±Ç°²Ù×÷µÄÊý¾Ý¿âÁ´½Ó
*/
var $currConn = null;
/**
* ÊÇ·ñÖ»ÓÐһ̨MasterÊý¾Ý¿â·þÎñÆ÷
*/
var $singleHost = true;
/**
* Êý¾Ý¿â½á¹û
*/
var $dbResult;
/**
* Êý¾Ý¿â²éѯ½á¹û¼¯
*/
var $dbRecord;

/**
* SQLÓï¾ä
*/
var $dbSql;
/**
* Êý¾Ý¿â±àÂë
*/
var $dbCharset = "UTF8";
/**
* Êý¾Ý¿â°æ±¾
*/
var $dbVersion = "5.0";


/**
* ³õʼ»¯µÄʱºòÊÇ·ñÒªÁ¬½Óµ½Êý¾Ý¿â
*/
var $isInitConn = false;


Ïà¹ØÎĵµ£º

mysql Êý¾Ý´æ´¢×ܽá

ÓÉÓÚ×î½üÒ»Ö±ÔÚÁ˽âmysql¡£¸÷ÖÖ±íÀàÐ͵ÄÊý¾Ý´æ´¢ÒÔ¼°Ïà¹ØÏÞÖÆ¾ÍÊDZØÐëÁ˽âµÄ·½ÃæÁË¡£
×Ô¼ºµÄ·þÎñÆ÷»·¾³£ºOS Cent OS ext3£¬memory 4G£¬ disk 2T block size 4K¡£
¾­µ÷²é£¬linuxÏÂÎļþ×î´óÊÇ´æÔÚÏÞÖÆµÄ¡£È¥googleÉÏËÑÁËËÑ£¬´ó¼Ò˵·¨²»Ò»£¬×îÖÕ×Ô¼º»¹ÊÇÕÒµ½±È½Ï¹Ù·½µÄ˵¡£Ïê¼ûhttp://en.wikipedia.org/wiki/Ext3 ËùÒÔ× ......

Mysql³£ÓÃÃüÁî½Å±¾

Mysql³£ÓÃÃüÁî½Å±¾
µÚÒ»ÕС¢mysql·þÎñµÄÆô¶¯ºÍÍ£Ö¹
net stop mysql
net start mysql
µÚ¶þÕС¢µÇ½mysql
Óï·¨ÊÇ mysql -hÖ÷»ú -uÓû§Ãû -pÃØÃÜ
Àý×ÓÊÇ mysql -hlocalhost -uroot -p123456
Ҫȷ¶¨mysql°²×°Ê±ºò¹´Ñ¡ÁË¿ÉÒÔÔ¶³ÌÁ´½Ó¡£Èç¹ûµÇ½±¾µØ¼ÆËã»ú£¬-h¿ÉÒÔÊ¡ÂÔ£¬¼üÈëÃüÁîmysql -uroot -p£¬ »Ø³µºóÌáʾÄãÊäÈëÃÜÂ룬 ......

Mysql ʱ¼äº¯Êý»ã×Ü

 Ò»¡¢MySQL »ñµÃµ±Ç°ÈÕÆÚʱ¼ä º¯Êý
1.1 »ñµÃµ±Ç°ÈÕÆÚ+ʱ¼ä£¨date + time£©º¯Êý£ºnow()
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2008-08-08 22:20:46 |
+---------------------+
³ýÁË now() º¯ÊýÄÜ»ñµÃµ±Ç°µÄÈÕÆÚʱ¼äÍ⣬MySQL Öл¹ÓÐÏÂÃæµÄº¯Êý£º
current_tim ......

mysql²Ù×÷ Left join , Right Join, Inner Join


Ò».ÏÈ¿´Ò»Ð©×î¼òµ¥µÄÀý×Ó
Àý×Ó
Table A
aid   adate
1      a1
2      a2
3      a3
TableB
bid bdate
1    b1
2   b2
4    b4
Á½¸ö±ía,bÏàÁ¬½Ó,Ҫȡ ......

MySQL¶Ô±ê×¼SQLµÄÀ©Õ¹

MySQL·þÎñÆ÷°üº¬Ò»Ð©ÆäËûSQL DBMSÖв»¾ß±¸µÄÀ©Õ¹¡£×¢Ò⣬Èç¹ûʹÓÃÁËËüÃÇ£¬½«ÎÞ·¨°Ñ´úÂëÒÆÖ²µ½ÆäËûSQL·þÎñÆ÷¡£ÔÚijЩÇé¿öÏ£¬Äã¿ÉÒÔ±àд°üº¬MySQLÀ©Õ¹µÄ´úÂ룬µ«ÈÔ±£³ÖÆä¿ÉÒÆÖ²ÐÔ£¬·½·¨ÊÇÓÓ/*... */”×¢Ê͵ôÕâЩÀ©Õ¹¡£MySQL·þÎñÆ÷Äܹ»½âÎö²¢Ö´ÐÐ×¢ÊÍÖеĴúÂ룬¾ÍÏñ¶Ô´ýÆäËûMySQLÓï¾äÒ»Ñù£¬µ«ÆäËûSQL·þÎñÆ÷½«ºöÂÔ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ