mysql ½¨Á¢Ë÷Òý
¾ÍÏóÐí¶àµÄPHP¿ª·¢ÕßÒ»Ñù£¬ÔÚ¸Õ¿ªÊ¼½¨Á¢¶¯Ì¬ÍøÕ¾µÄʱºò£¬ÎÒ¶¼ÊÇʹÓÃÏà¶Ô¼òµ¥
µÄÊý¾Ý½á¹¹¡£PHPÔÚÁ¬½ÓÊý¾Ý¿â·½ÃæµÄȷʵÊÇÊ®·Ö·½±ã£¨ÒëÕß×¢£ºÓÐЩÈËÈÏΪPHPÔÚÁ¬½Ó²»Í¬Êý¾Ý¿âʱûÓÐÒ»¸öͳһµÄ½Ó¿Ú£¬²»Ì«·½±ã£¬ÆäʵÕâ¿ÉÒÔͨ¹ýһЩÀ©
Õ¹¿âÀ´×öµ½ÕâÒ»µã£©£¬ÄãÎÞÐè¿´´óÁ¿µÄÉè¼ÆÎĵµ¾Í¿ÉÒÔ½¨Á¢ºÍʹÓÃÊý¾Ý¿â£¬ÕâÒ²ÊÇPHP»ñµÃ³É¹¦µÄÖ÷ÒªÔÒòÖ®Ò»¡£
ǰЩʱºò£¬Ò»Î»Æĸ߼¶
µÄ³ÌÐòÔ±¾ÓÈ»ÎÊÎÒʲô½Ð×öË÷Òý£¬ÁîÎҸе½Ê®·ÖµÄ¾ªÆ棬ÎÒÏëÕâ¾ø²»»áÊDz׺£Ò»ËÚ£¬ÒòΪÓгÉǧÉÏÍòµÄ¿ª·¢Õߣ¨¿ÉÄܴ󲿷ÖÊÇʹÓÃMySQLµÄ£©¶¼Ã»ÓÐÊܹýÓйØÊý
¾Ý¿âµÄÕý¹æÅàѵ£¬¾¡¹ÜËûÃǶ¼Îª¿Í»§×ö¹ýһЩ¿ª·¢£¬µ«È´¶ÔÈçºÎΪÊý¾Ý¿â½¨Á¢Êʵ±µÄË÷ÒýËùÖª½ÏÉÙ£¬Òò´ËÎÒÆðÁËдһƪÏà¹ØÎÄÕµÄÄîÍ·¡£
×îÆÕͨµÄÇé¿ö£¬ÊÇΪ³öÏÖÔÚwhere×Ó¾äµÄ×ֶν¨Ò»¸öË÷Òý¡£Îª·½±ã½²Êö£¬ÎÒÃÇÏȽ¨Á¢Ò»¸öÈçÏÂµÄ±í¡£
Code´úÂëÈçÏÂ:
CREATE TABLE mytable (
¡¡id serial primary key,
¡¡category_id int not null default 0,
¡¡user_id int not null default 0,
¡¡adddate int not null default 0
);
ºÜ¼òµ¥°É£¬²»¹ý¶ÔÓÚҪ˵Ã÷Õâ¸öÎÊÌ⣬ÒѾ×ã¹»ÁË¡£Èç¹ûÄãÔÚ²éѯʱ³£ÓÃÀàËÆÒÔϵÄÓï¾ä£º
SELECT * from mytable WHERE category_id=1;
×îÖ±½ÓµÄÓ¦¶ÔÖ®µÀ£¬ÊÇΪcategory_id½¨Á¢Ò»¸ö¼òµ¥µÄË÷Òý£º
CREATE INDEX mytable_categoryid
¡¡ON mytable (category_id);
OK£¬¸ã¶¨£¿Ïȱð¸ßÐË£¬Èç¹ûÄãÓв»Ö¹Ò»¸öÑ¡ÔñÌõ¼þÄØ£¿ÀýÈ磺
SELECT * from mytable WHERE category_id=1 AND user_id=2;
ÄãµÄµÚÒ»·´Ó¦¿ÉÄÜÊÇ£¬ÔÙ¸øuser_id½¨Á¢Ò»¸öË÷Òý¡£²»ºÃ£¬Õâ²»ÊÇÒ»¸ö×î¼ÑµÄ·½·¨¡£Äã¿ÉÒÔ½¨Á¢¶àÖصÄË÷Òý¡£
CREATE INDEX mytable_categoryid_userid ON mytable (category_id,user_id);
×¢Òâµ½ÎÒÔÚÃüÃûʱµÄÏ°¹ßÁËÂð£¿ÎÒʹÓÃ"±íÃû_×Ö¶Î1Ãû_×Ö¶Î2Ãû"µÄ·½Ê½¡£ÄãºÜ¿ì¾Í»áÖªµÀÎÒΪʲôÕâÑù×öÁË¡£
ÏÖÔÚÄãÒѾΪÊʵ±µÄ×ֶν¨Á¢ÁËË÷Òý£¬²»¹ý£¬»¹ÊÇÓе㲻·ÅÐÄ°É£¬Äã¿ÉÄÜ»áÎÊ£¬Êý¾Ý¿â»áÕæÕýÓõ½ÕâЩË÷ÒýÂ𣿲âÊÔһϾÍOK£¬¶ÔÓÚ´ó¶àÊýµÄÊý¾Ý¿âÀ´Ëµ£¬ÕâÊǺÜÈÝÒ׵ģ¬Ö»ÒªÊ¹ÓÃEXPLAINÃüÁ
EX
Ïà¹ØÎĵµ£º
ÔÚÊý¾Ý¿âÓ¦Óã¬ÎÒÃǾ³£ÒªÓõ½Î¨Ò»±àºÅ¡£ÔÚMySQLÖпÉͨ¹ý×ֶεÄAUTO_INCREMENTÊôÐÔÀ´×Ô¶¯Éú³É¡£MySQLÖ§³Ö¶àÖÖÊý¾Ý±í£¬Ã¿ÖÖÊý¾Ý±íµÄ×ÔÔöÊôÐÔ¶¼ÓÐËù²»Í¬¡£
ISAM±í
Èç¹û°ÑÒ»¸öNULL²åÈëµ½Ò»¸öAUTO_INCREMENTÊý¾ÝÁÐÀïÈ¥£¬MySQL½«×Ô¶¯Éú³ÉÏÂÒ»¸öÐòÁбàºÅ¡£±àºÅ´Ó1¿ªÊ¼£¬²¢1Ϊ»ùÊýµÝÔö¡£
µ±²åÈë¼Ç¼ʱ£¬Ã»ÓÐΪAUTO_INCREMENTÃ÷È ......
»ù´¡²¿·Ö
Ò»¡¢MySQL »ñµÃµ±Ç°ÈÕÆÚʱ¼ä º¯Êý
1.1 »ñµÃµ±Ç°ÈÕÆÚ+ʱ¼ä£¨date + time£©º¯Êý£ºnow()
mysql> select now();
+---------------------+
| now() |
+----------------- ......
2007-11-16 15:37
½ñÌì¿´×ÅÊÖ²áÊÔÁËÏ£¬·¢ÏÖÔÀ´´óÊý¾Ýµ¼Èëµ¼³öÊÇÄÇôµÄÇáËÉ£¨²»ÊǺܴó£¬200¶àMµÄÎı¾¶øÒÔ£©
×¢Ò⣺Èç¹û·¢ÏÖMYSQL unknown command '\'ÕâÑùµÄÌáʾ£¬ÔòÉèÖÃһϷþÎñÆ÷µÄ×Ö·û¼¯£¬È磺
mysql -uroot -ppasspass --default-character-set=utf8 databaseName <d:bakcup.sql
ÕâÑù¾Í²»»á±¨´íÁË£¬^_^
µ¼³ö ......
ÈçÈôתÔØ£¬Çë×ðÖظöÈËÀͶ¯£¬Îñ±Ø×¢Ã÷Ôʼ³ö´¦£º(http://blog.csdn.net/iihero/archive/2010/05/13/5585039.aspx)
±¾ÎÄΪiihero@CSDNÔ´´¡£
ÔÚǰһƪ¶ÌÎÄÀïÌáµ½ÁËmy.ini/cnfµÄ¼ÓÔØ˳Ðò£ºC:\WINDOWS\my.cnf->C:\WINDOWS\my.ini->C:\my.cnf ->C:\my.ini ->$installdir\my.ini¡£(%MYSQL_HOME%\my.ini)-> ......
#include "winsock.h"
#include "mysql.h"
void query_example(void)
{
MYSQL *pDbCon = NULL;
char *pszHost = "localhost";
char *pszUser = "guest";
char *pszPsw = "";
char *pszDbName = "mysql_db_name";
int iPort = 3306;
pDbCon = mysql_init((MYSQL*) 0);
if (NULL != pDbCon)
{
......