ÕýÈ·Àí½âMysqlµÄÁÐË÷ÒýºÍ¶àÁÐË÷Òý
MysqlÊý¾Ý¿âÌṩÁ½ÖÖÀàÐ͵ÄË÷Òý£¬Èç¹ûûÕýÈ·ÉèÖã¬Ë÷ÒýµÄÀûÓÃЧÂÊ»á´ó´òÕÛ¿ÛÈ´ÍêÈ«²»ÖªÎÊÌâ³öÔÚÕâ¡£
CREATE TABLE test (
id INT NOT NULL,
last_name CHAR(30) NOT NULL,
first_name CHAR(30) NOT NULL,
PRIMARY KEY (id),
INDEX name (last_name,first_name)
);
ÒÔÉÏ´´½¨µÄÆäʵÊÇÒ»¸ö¶àÁÐË÷Òý£¬´´½¨ÁÐË÷ÒýµÄ´úÂëÈçÏ£º
CREATE TABLE test (
id INT NOT NULL,
last_name CHAR(30) NOT NULL,
first_name CHAR(30) NOT NULL,
PRIMARY KEY (id),
INDEX name (last_name),
INDEX_2 name (first_name)
);
Ò»¸ö¶àÁÐË÷Òý¿ÉÒÔÈÏΪÊÇ°üº¬Í¨¹ýºÏ²¢(concatenate)Ë÷ÒýÁÐÖµ´´½¨µÄÖµµÄÒ»¸öÅÅÐòÊý×é¡£ µ±²éѯÓï¾äµÄÌõ¼þÖаüº¬last_name ºÍ first_nameʱ£¬ÀýÈ磺
SELECT * from test WHERE last_name='Kun' AND first_name='Li';
sql»áÏȹýÂ˳ölast_name·ûºÏÌõ¼þµÄ¼Ç¼£¬ÔÚÆä»ù´¡ÉÏÔÚ¹ýÂËfirst_name·ûºÏÌõ¼þµÄ¼Ç¼¡£ÄÇÈç¹ûÎÒÃÇ·Ö±ðÔÚlast_nameºÍfirst_nameÉÏ´´½¨Á½¸öÁÐË÷Òý£¬mysqlµÄ´¦Àí·½Ê½¾Í²»Ò»ÑùÁË£¬Ëü»áÑ¡ÔñÒ»¸ö×îÑϸñµÄË÷ÒýÀ´½øÐмìË÷£¬¿ÉÒÔÀí½âΪ¼ìË÷ÄÜÁ¦×îÇ¿µÄÄǸöË÷ÒýÀ´¼ìË÷£¬ÁíÍâÒ»¸öÀûÓò»ÉÏÁË£¬ÕâÑùЧ¹û¾Í²»Èç¶àÁÐË÷ÒýÁË¡£
µ«ÊǶàÁÐË÷ÒýµÄÀûÓÃÒ²ÊÇÐèÒªÌõ¼þµÄ£¬ÒÔÏÂÐÎʽµÄ²éѯÓï¾äÄܹ»ÀûÓÃÉ϶àÁÐË÷Òý£º
SELECT * from test WHERE last_name='Widenius';
SELECT * from test WHERE last_name='Widenius' AND first_name='Michael';
SELECT * from test WHERE last_name='Widenius' AND (first_name='Michael' OR first_name='Monty');
SELECT * from test WHERE last_name='Widenius' AND first_name >='M' AND first_name < 'N';
ÒÔÏÂÐÎʽµÄ²éѯÓï¾äÀûÓò»É϶àÁÐË÷Òý£º
SELECT * from test WHERE first_name='Michael';
SELECT * from test WHERE last_name='Widenius' OR first_name='Michael';
¶àÁн¨Ë÷Òý±È¶Ôÿ¸öÁзֱð½¨Ë÷Òý¸üÓÐÓÅÊÆ£¬ÒòΪË÷Òý½¨Á¢µÃÔ½¶à¾ÍÔ½Õ¼´ÅÅ̿ռ䣬ÔÚ¸üÐÂÊý¾ÝµÄʱºòËٶȻá¸üÂý¡£
ÁíÍ⽨Á¢¶àÁÐË÷Òýʱ£¬Ë³ÐòÒ²ÊÇÐèҪעÒâµÄ£¬Ó¦¸Ã½«ÑϸñµÄË÷Òý·ÅÔÚÇ°Ã棬ÕâÑùɸѡµÄÁ¦¶È»á¸ü´ó£¬Ð§Âʸü¸ß¡£
Ïà¹ØÎĵµ£º
²Î¼û¹Ù·½²Î¿¼£¬µÚ25Õ£ºAPIºÍ¿â
25.2.3.49. mysql_ping()
int
mysql_ping(MYSQL *mysql)
ÃèÊö
¼ì²éÓë·þÎñÆ÷µÄÁ¬½ÓÊÇ·ñ¹¤×÷¡£Èç¹ûÁ¬½Ó¶ªÊ§£¬½«×Ô¶¯³¢ÊÔÔÙÁ¬½Ó¡£
¸Ãº¯Êý¿É±»ÏÐÖÃÁ˽ϳ¤Ê±¼äµÄ¿Í»§¶ËʹÓã¬ÓÃÒÔ¼ì²é·þÎñÆ÷ÊÇ·ñÒѹرÕÁËÁ¬½Ó£¬²¢ÔÚ±ØҪʱÔÙ´ÎÁ¬½Ó¡£
·µ»ØÖµ
Èç¹ûÓë·þÎñÆ÷µÄÁ¬½ÓÓÐЧ·µ»Ø ......
MySQLÓкܶà¿ÉÒÔµ¼ÈëÊý¾ÝµÄ·½·¨£¬È»¶øÕâЩֻÊÇÊý¾Ý´«ÊäÖеÄÒ»°ë£¬ÁíÍâµÄÒ»°ãÊÇ´ÓMySQLÊý¾Ý¿âÖе¼³öÊý¾Ý¡£ÓÐÐí¶àµÄÔÒòÎÒÃÇÐèÒªµ¼³öÊý¾Ý¡£Ò»¸öÖØ
ÒªµÄÔÒòÊÇÓÃÓÚ±¸·ÝÊý¾Ý¿â¡£Êý¾ÝµÄÔì¼Û³£³£ÊÇ°º¹óµÄ£¬ÐèÒª½÷É÷´¦ÀíËüÃÇ¡£¾³£µØ±¸·Ý¿ÉÒÔ°ïÖú·ÀÖ¹±¦¹óÊý¾ÝµØ¶ªÊ§£»ÁíÍâÒ»¸öÔÒòÊÇ£¬Ò²ÐíÄúÏ£Íûµ¼³öÊý¾ÝÀ´¹²
Ïí¡£ ÔÚÕâ¸öÐÅÏ¢¼¼Ê ......
1¡¢ÔÚlinuxÏ£º
²é¿´mysql ÊÇ·ñÔËÐУºps -ef | grep myslq
Èç¹û MySQL ÕýÔÚÔËÐУ¬Ê×ÏÈɱ֮: kill mysqlµÄ½ø³ÌºÅ¡£
¡¡¡¡Æô¶¯ MySQL :/usr/bin/safe_mysqld --skip-grant-tables &
¡¡¡¡¾Í¿ÉÒÔ²»ÐèÒªÃÜÂë¾Í½øÈë MySQL ÁË¡£
¡¡¡¡È»ºó¾ÍÊÇ
¡¡¡¡>use mysql
¡¡¡¡ ......
½â¾öÂÒÂë×îºÃµÄ·½·¨ÊÇÔÚÏîÄ¿Éè¼ÆÖ®³õ£¬Í³Ò»ËùÓеÄ×Ö·û¼¯£¬ÀýÈçÒ³Ãæ¡¢request¶ÔÏóÒÔ¼°Êý¾Ý¿âµÈµÈ¡£
Ò»¡¢ ¼¸ÖÖ³£¼ûµÄÂÒÂëÏÖÏó£º
1¡¢Ò³ÃæÂÒÂë
µ¥´¿µÄÒ³ÃæÂÒÂëÊǺܺýâ¾öµÄ£¬Ö»ÒªÐÞ¸ÄÍ·²¿ÊʺϵÄ×Ö·û¼¯¼´¿É£¬Èç¹ûÒ³ÃæÖÐÎÄÏÔʾÂÒÂ룬Äã¿ÉÒÔ°Ñ×Ö·û¼¯ÐÞ¸ÄΪ£ºgb2312»ògbk¡£
2¡¢Ò³ÃæÖ®¼ä´«µÝµÄ²ÎÊýÊÇÂÒÂë ......
#include <stdio.h>
#include <windows.h>
#include <mysql.h>
#define host "localhost"
#define username "root"
#define password "123"
#define database "oa"
MYSQL *conn;
int main()
{
MYSQL_RES *res_set;
MYSQL_ROW row;
unsigned int i,ret;
FILE *fp;
MYSQL_FIELD *field;
......