Linux C MySQLÊý¾Ý¿âº¯Êý
1. ³õʼ»¯Ò»¸öÁ¬½Ó¾ä±ú
MYSQL *mysql_init(MYSQL *);
ÕýÈ·£º·µ»ØÒ»¸öÖ¸ÏòзÖÅäµÄÁ´½Ó¾ä±ú½á¹¹µÄÖ¸Õë
´íÎó£ºNULL
×¢£º¸Ãº¯ÊýµÄ´«Èë²ÎÊýͨ³£ÎªNULL¼´¿É¡£
2. ½¨Á¢ÎïÀíÁ¬½Ó
MYSQL *mysql_real_connect(MYSQL *connection,
const char *server_host,
const char *sql_user_name,
const char *sql_password,
const char *db_name,
unsigned int port_number,
const char *unix_socket_name,
unsigned int flags);
ÆäÖÐconnection²ÎÊýΪͨ¹ýmysql_initº¯Êý´´½¨µÄ¾ä±ú£¬server_host²ÎÊý¿ÉΪÖ÷»úÃû»òIPÖµ£¬Èç¹ûÁ¬µ½±¾»ú£¬ÎÒÃǽö½öÖ»ÐèÖ¸¶¨“localhost”¼´¿É¡£sql_user_nameºÍsql_password¼´Îª·ÃÎÊÊý¾Ý¿âµÄÓû§ÃûºÍÃÜÂ룬Èç¹ûsql_user_nameΪ¿Õ£¬ÄÇôĬÈÏΪµ±Ç°Linux userµÄÓû§Ãû£¬Èç¹ûsql_passwordΪ¿Õ£¬ÄÇôֻÄÜ·ÃÎʲ»ÐèÒªÃÜÂëµÄÊý¾Ý¡£ÃÜÂëÔÚ¾ÍøÂç´«Êä֮ǰ¶¼¾¹ý¼ÓÃÜ´¦Àí¡£Í¨³£Çé¿öÏ£¬Èç¹ûÄãûÓиıäMySQLµÄĬÈÏ°²×°£¬port_numberºÍ*unix_socket_nameµÄÖµ·Ö±ðΪ0ºÍNULL¼´¿É£¬ËûÃÇĬÈÏΪµ±Ç°ÏàÓ¦Öµ¡£flags²ÎÊýÔÊÐíÎÒÃǸı䵱ǰʹÓÃÐÒéµÄÌØÐÔ£¬Ä¬ÈÏÇé¿öÏ£¬ÖÃ0¼´¿É¡£
Èç¹ûÁ¬½Ó²»³É¹¦£¬¸Ãº¯Êý·µ»ØNULL
3. ¶Ï¿ªÁ¬½Ó
void mysql_close(MYSQL *connection);
ʹÓøú¯Êý¿ÉÒԶϿªÖ¸¶¨µÄÁ´½Ó¡£²»Èò»ÐèÒªµÄÁ¬½Ó¶Ï¿ª»áÀË·Ñ×ÊÔ´£¬µ«ÖØн¨Á¢Á¬½ÓÐèÒª¶îÍ⿪Ïú£¬ÔÚʵ¼Ê¹¤×÷ÖÐÎÒÃǿɸù¾ÝÐèҪȨºâ¡£
4. Ñ¡ÏîÉèÖÃ
int mysql_options(MYSQL *connection, enum option_to_set,
const char *argument);
¸Ãº¯Êý¿ÉÓÃÔÚmysql_initºÍmysql_real_connectÖ®¼äÀ´ÉèÖÃһЩÁ¬½ÓÑ¡Ïoption_to_set²ÎÊýÈçMYSQL_OPT_CONNECT_TIMEOUTÓÃÀ´ÉèÖÃÁ¬½Ó³¬Ê±µÄʱ¼ä(Ãë)£¬MYSQL_OPT_COMPRESS±íʾÔÚÍøÂç´«ÊäÖжÔÊý¾Ý½øÐÐѹËõ£¬¶øMYSQL_INIT_COMMANDÖ¸¶¨Ã¿µ±Á¬½Ó½¨Á¢Ê±ÓÃÀ´·¢Ë͵ÄÃüÁî¡£
º¯Êý³É¹¦Ê±·µ»Ø0£¬ÒòΪ¸Ãº¯Êý½ö½öÓÃÀ´ÉèÖÃÑ¡ÏËùÒÔʧ°ÜÒâζ×ÅʹÓÃÁËÎÞЧµÄÑ¡Ïî¡£´ËÍ⣬¸Ãº¯Êýÿ´ÎÖ»ÄÜÉèÖÃÒ»ÖÖÑ¡ÏËùÒÔÿÉèÖÃÒ»¸öÑ¡Ïî¾Í±ØÐëµ÷Óøú¯ÊýÒ»´Î¡£
¾ÙÀý£º
unsigned int timeout = 7;
connection = mysql_init(NULL);
Ïà¹ØÎĵµ£º
×¢: ´ÓMySQL´Ó·þÎñÆ÷µÄ°æ±¾²»ÄÜСÓÚÖ÷·þÎñÆ÷µÄ°æ±¾ ʵÑé»·¾³ Master Mysql·þÎñÆ÷°æ±¾5.1.36,IP:192.168.128.130 Slave Mysql·þÎñÆ÷°æ±¾5.1.36,IP:192.168.128.132 Ò». MySQLÖ÷·þÎñÆ÷ÅäÖà 1.½¨Á¢ÊÚȨÓû§ Ó÷¨:grant replication slave on *.* to ¡®Óû§Ãû¡¯@'Ö÷»ú¡¯ identified by ¡®ÃÜÂ롯; mysql>grant replicatio ......
Ìí¼Ó×ֶεĸñʽ
ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name alter_specification [, alter_specification] ...alter_specification: table_option ... | ADD [COLUMN] col_name column_definition [FIRST | AFTER col_name ]
eg.
ALTER TABLE myTbl ADD COLUMN newItem VARCHAR(20) DEFAULT "0" ......
ÁªºÏMySQL Proxy ºÍMySQL Cluster£¬¹¹½¨¸ßÐÔÄÜÊý¾Ý¿â
ÔÎÄ£ºhttp://blogs.mysql.com/kaj/2007/12/10/combining-mysql-proxy-with-mysql-cluster/
²»¾ÃÇ°£¬ÎÒºÍStewart Smith, Vinay Joosery, Monty Taylor ÒÔ¼°ÆäËûµÄmysqlʹÓÃÕߣ¨ËûÃDZÈÎÒ¸üÊìϤMySQL Cluster £©Õ¹¿ªÁËÒ»´ÎÌÖÂÛ£ ......
¶Ô±ÈcharºÍvarcharËæ±ãÔÚgoogle»ò°Ù¶ÈÖÐËÑһϵõ½µÄ½áÂÛ´ó¸Å¶¼ÊÇ"char¶¨³¤,varchar²»¶¨³¤,charÒª±ÈvarcharÕ¼Óøü¶àµÄ¿Õ¼ä,ÓÉÓÚ¶¨³¤charµÄЧÂʸßÓÚvarchar,char×î´ó255,varchar×î´ó65536"¸ü¸ß¼¶Ò»µãµÄÊý¾ÝÊÇ"charÔÚ´æÈëºÍÈ¡³öµÄʱºò,»á×Ô¶¯°ÑĩβµÄ¿Õ¸ñÈ¥µô,varchar»á¶îÍâµÄ¶àÓÃ1-2¸ö×Ö½ÚÀ´´æ·Å×Ö·û³¤¶È,ÁÐÖÐÓÐÒ»¸övarchar» ......