.net·ÃÎÊMysqlһЩϸ½ÚÎÊÌâ
²ÉÓõÄÊÇMySql¹Ù·½ÌṩµÄ.NET connector£¬´ËÇý¶¯Ö»ÐèÒªÏÂÔؼ´¿ÉʹÓãºhttp://dev.mysql.com/downloads/connector/net/1.0.html
ÔÚʹÓÃÖлýÀÛÁ˼¸µã¾Ñ飺
1)ʹÓÃParameter²ÎÊýÐÎʽÌá½»Commandʱ±ØÐëÒª°Ñ"@"ºÅ»»³É"?"ºÅ£¬ÕâÒ»µãÈÃÎÒÀ§»óÁËÒ»Ì죬ֻÊDz»Ã÷°×MySQLΪºÎÒª¸ãÌØÊâÄØ£¬ÏóMS¡¢ODP.NET for Oracle¡¢OleDbµÈ·½Ê½£¬¶¼ÊÇÓÃ"@"ºÅµÄ¡£
Àý×ÓÈçÏ£º
string connstr=Setting.Instance().GetConnectionString("MySql");
MySqlConnection conn =new MySqlConnection(connstr);
conn.Open();
string query = "insert into myfirst(Id,Name) values(?Id,?Name)";
MySqlCommand cmd = new MySqlCommand(query, conn);
MySqlParameter para1=new MySqlParameter("?Id",DbType.Int32); //ÕâÀïҪעÒâ±ØÐëÒªÓÃ?ºÅ
MySqlParameter para2=new MySqlParameter("?Name",DbType.String);//ÕâÀïҪעÒâ±ØÐëÒªÓÃ?ºÅ
para1.Value=5;
para2.Value="ddd";
cmd.Parameters.Add(para1);
cmd.Parameters.Add(para2);
cmd.ExecuteNonQuery();
2)ÔÚMySQLÖÐÒ²Óб£Áô×Ö£¬ÎªÁËÌṩ¼æÈÝ£¬ÎÒ±ØÐëÒªÕÒµ½¶¨½ç·û£¬ºÃ²»ÈÝÒ×ÔÚMySqlµÄÂÛ̳ÀïÕÒµ½ÁË£¬Ê¹ÓõĶ¨½ç·ûÊÇ`£¬Õâ¸ö·ûºÅ²»Êǵ¥ÒýºÅ£¬¶øÊǼüÅÌÉÏÊý×Ö1Ç°ÃæµÄÄǸö“µã”£¬ÕæÊǺ¦ËÀÎÒ°¡¡£
3£©MySQLÖеÄTOP¹¦Äܵ¹ÊǷdz£¼òµ¥£¬Ö»ÐèÒªÓï¾äºóÃæʹÓÓlimit n”¾ÍÐÐÁË£¬Õâ±ÈORACLEµÄÄÇRownum·½±ã¶àÁË¡£
ʹÓÃMySql µÄ.NET Connector·ÃÎÊMySQL×ÜÌåÀ´Ëµ»¹Ëã²»´íµÄ£¬´ó²¿·ÖÊǼæÈÝ.NETÖеÄIConnection¡¢ICommandµÄ¡£
PS£ºÓиö²»Ã÷°×¾ÍÊÇÔÚ.NET ConnectorÖÐÌṩһ¸öMySqlDateTimeÀ࣬²»ÖªµÀÕâ¸öÀà¾ßÌåÓÐʲôÓã¬ÔõôÓã¬ÔÚ¹úÄÚûÓÐÕÒµ½Ïà¹ØµÄ×ÊÁÏ¡£MySqlDateTime¸úSystem.Date»¹²»¼æÈÝ£¬ÔÚMySQLÂÛ̳ÉÏÏà¹ØÌû×ÓN¶à¡£
Èç¹û²ÉÓÃStringÀàÐ͵ÄParameter´«µÝ¸øMySqlµÄDateTime×ֶλᱨ£ºUnable to Convert MySql Date/Time value to System.DateTime µÄ´íÎó¡£
MysqlÓï¾ä¼Ó ×Ö¶ÎÓС¾¡¿ ¾Í»á±¨´íÎ󣡣¡£¡£¡£¡£¡£¡
Ò²ÊǸտªÊ¼Ñ§mysql,ÏÂÃæÊÇÎÒ´ÓÍøÉÏÕÒµ½µÄ,ÎÒ¸Õ²ÅÊÔ¹ýÁË,¿ÉÒÔ, ÎÒµÄÊÇmysql5.0µÄ
mysql ·þÎñÆ÷Ö§³Ö # µ½¸ÃÐнáÊø¡¢-- µ½¸ÃÐнáÊø ÒÔ¼° /* ÐÐÖмä»ò¶à¸öÐÐ */ µÄ×¢ÊÍ·½¸ñ£º
mysql> SELECT 1+1; # Õâ¸ö×¢ÊÍÖ±
Ïà¹ØÎĵµ£º
1.ʲôÊÇUDF? UDF(user-defined function)ÊÇmysqlΪÓû§ÌṩµÄ×Ô¶¨Ò庯ÊýµÄÀ©Õ¹½Ó¿Ú¡£Ëü±¾ÖÊÉϺÍmysqlÌṩµÄmax¡¢minºÍcountµÈº¯ÊýÀàËÆ¡£ 2.UDF¿ÉÒÔ×öʲô? UDFÊÇ×Ô¶¨Ò庯Êý£¬ËùÒÔËüÄÜ×öʲôÍêÈ«È¡¾öÓÚÄãµÄʵÏÖ¡£UDF¿ÉÒÔÔÚÆÕͨµÄsql¡¢triggerÒÔ¼°store procedure±»µ÷ÓᣠÈç¹û×Ô¶¨ÒåÒ»¸ötcp_send(ip,port,msg)µ ......
MySQLÅäÖÃÎļþ
MySQL·¢²¼µÄ×îвúƷʵ¼ÊÉϳ¬³öÁËLinuxËùЯ´øµÄ°æ±¾¡£µ«ÊÇ£¬Îȶ¨ÐԺͿª·ÅÔ´´úÂë¿ÉÊǺÜÖØÒªµÄÒòËØ£¬Òò´ËÔÚ²Ù×÷ϵͳÉÏʹÓýÏÔçMySQL°æ±¾ÊÇÓеÀÀíµÄ¡£
ÓÐÐí¶à¿ÉÒÔ²ÉÓõÄÅäÖÃÎļþ£¬ËüÃǶ¼±»°üº¬ÔÚmysql-server PRM³ÌÐòÖС£»¹ÓÐÒ»¸öĬÈϵÄÅäÖÃÎļþ±»°üº¬ÔÚmysql PRM³ÌÐò°üÖС£
ÅäÖÃMySQL·þÎñÆ÷ÊÇÒ»¸ö·á¸»¶ø¸´ÔÓ ......
TIMESTAMPÁÐÀàÐÍÌṩһÖÖÀàÐÍ£¬Äã¿ÉÒÔʹÓÃËü×Ô¶¯µØÓõ±Ç°µÄÈÕÆÚºÍʱ¼ä±ê¼ÇINSERT»òUPDATEµÄ²Ù×÷¡£Èç¹ûÄãÓжà¸öTIMESTAMPÁУ¬Ö»ÓеÚÒ»¸ö×Ô¶¯¸üС£
×Ô¶¯¸üеÚÒ»¸öTIMESTAMPÁÐÔÚÏÂÁÐÈκÎÌõ¼þÏ·¢Éú£º
ÁÐûÓÐÃ÷È·µØÔÚÒ»¸öINSERT»òLOAD DATA INFILEÓï¾äÖÐÖ¸¶¨¡£
ÁÐûÓÐÃ÷È·µØÔÚÒ ......
MySQL ÃüÁîÐÐ
µÚÒ»ÕС¢mysql·þÎñµÄÆô¶¯ºÍÍ£Ö¹
net stop mysql
net start mysql
µÚ¶þÕС¢µÇ½mysql
Óï·¨ÈçÏ£º mysql -uÓû§Ãû -pÓû§ÃÜÂë
¼üÈëÃüÁîmysql -uroot -p£¬ »Ø³µºóÌáʾÄãÊäÈëÃÜÂ룬ÊäÈë12345£¬È»ºó»Ø³µ¼´¿É½øÈëµ½mysqlÖÐÁË£¬mysqlµÄÌáʾ·ûÊÇ£º
mysql>
×¢Ò⣬Èç¹ûÊÇÁ¬½Óµ½ÁíÍâµÄ»úÆ÷ÉÏ£¬ÔòÐèÒª¼ÓÈëÒ»¸ö² ......
#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;
......