C#Á¬½ÓMySQL½øÐвÙ×÷µÄ·½·¨
ÓÉÓÚÐèҪʵÏÖÒÔϹ¦ÄÜ£º
Íø¹ØÍ¨¹ý´®¿Ú·¢ËÍÊý¾Ý¸øPC»ú£¬PC»úÊÕ¼¯Êý¾Ý²¢½âÎö±£´æµ½MySQLÖУ¬È»ºóJSPÒ³Ãæ¶ÁÈ¡MySQLÖеÄÊý¾Ý²¢ÏÔʾ¡£
ËùÒÔÀûÓÃC#Á¬½ÓMySQLÊý¾Ý³ÉΪÁ˱ØÐëÒª¾¹ýµÄ¹ý³Ì£¬Ôڴ˸øÓèÏêϸµÄ˵Ã÷¡£
1¡¢ÏÂÔØÐèÒªµÄÎļþMySQLDriverCS£¬ÏÂÔØµØÖ·Îª£ºhttp://sourceforge.net/projects/mysqldrivercs
2¡¢°²×°Îļþ£ºMySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.exe£¬ÔÚ°²×°¹ý³ÌÖÐÒ²Ðí»áÌáʾһ¸ö´íÎ󣬽ûֹдһ¸ödllÎļþ£¬ÄãÖ±½ÓºöÂԾͿÉÒÔÁË¡£
3¡¢½«°²×°ÎļþϵÄMySQLDriver.dllÎļþÌí¼Óµ½C#ÏîÄ¿µÄÒýÓÃÖС£
4¡¢È»ºóд¹«¹²´¦ÀíÀàÈçÏ£º
(1) Ê×ÏȵÃÒýÓÃÃüÃû¿Õ¼ä£º
using MySQLDriverCS;
using System.Data;
using System.Data.Odbc;
(2) д¹«¹²´¦ÀíÀà
public class SQLHelper
{
MySQLConnection conn = null;
MySQLCommand commn = null;
public MySQLConnection GetConnect()
{
conn = new MySQLConnection(new MySQLConnectionString("localhost", "wwater", "root", "123").AsString);
return conn;
}
public int RunMySQL(string sql)
{
int count = 0;
try
{
conn = GetConnect();
conn.Open();
commn = new MySQLCommand(sql, conn);
count = commn.ExecuteNonQuery();
return count;
}
catch (Exception ex)
{
throw;
}
finally
{
conn.Close();
}
}
}
(3) ÔÚʵ¼Ê¹ý³ÌÖнøÐÐÒýÓÃRunMySQL·½·¨¼´¿É²åÈëÊý¾ÝÁË¡£
Ïà¹ØÎĵµ£º
/// <summary>
/// ·½·¨Ò»:ͨ¹ýʹÓà new ÔËËã·û´´½¨¶ÔÏó
/// </summary>
/// <param name="strSource">ÐèÒª¼ÓÃܵÄÃ÷ÎÄ</param>
/// <returns>·µ»Ø16λ¼ÓÃܽá¹û£¬¸Ã½á¹ûÈ¡32λ¼ÓÃܽá¹ûµÄµÚ9λµ½25λ</returns>
public string Get_MD5_Method1(strin ......
mysql ´´½¨±í£º
mysql> create table user(
-> userid int(4) primary key not null auto_increment,
-> username varchar(16) not null,
-> userpassword varchar(32) not null
-> );
create table log(
logid int(4) ......
//Ö÷¼ü
alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);
//Ôö¼ÓÒ»¸öÐÂÁÐ
alter table t2 add d timestamp;
alter table infos add ex tinyint not null default '0';
//ɾ³ýÁÐ
alter table t2 drop column c;
//ÖØÃüÃûÁÐ
......
MySQL5.X¶¼ÒѾ·¢²¼ºÃ¾ÃÁË£¬µ«ÊÇ»¹ÓкܶàÈËÈÏΪMySQLÊDz»Ö§³ÖÊÂÎñ´¦ÀíµÄ£¬Õâ²»µÃ²»¹ÖËûÃÇÊǹª¹ÑÎŵ쬯äʵ£¬Ö»ÒªÄãµÄMySQL°æ±¾
Ö§³ÖBDB»òInnoDB±íÀàÐÍ£¬ÄÇôÄãµÄMySQL¾Í¾ßÓÐÊÂÎñ´¦ÀíµÄÄÜÁ¦¡£ÕâÀïÃæ£¬ÓÖÒÔInnoDB±íÀàÐÍÓõÄ×î¶à£¬ËäÈ»ºóÀ´·¢ÉúÁËÖîÈçOracleÊÕ
¹ºInnoDBµÈÁîMySQL²»Ë¬µÄÊÂÇ飬µ«ÄÇЩÉÌÒµÉϵĶ·ÕùÓë¼¼ÊõÎÞ¹ ......
¾Ý¹úÍâýÌ屨µÀ£¬MySQLÊý¾Ý¿âµÄ¿ª·¢ÕßMichael WideniusÒÔ¼°²¿·ÖÏà¹ØÈËÊ¿½üÈÕÏòÅ·ÖÞ¡¢ÖйúÓë¶íÂÞ˹µÄ¼à¹Ü»ú¹¹Ìá½»Á˶Լ׹ÇÎÄ-Sun½»Ò׵ķ´¶ÔÒâ¼û£¬ÓдóÔ¼14000ÈËÔÚ¸ÃÒâ¼ûÉÏÇ©×Ö±íʾËûÃǶԴËÊÕ¹ºµÄ·´¶Ô¡£Å·ÃËίԱ»á´ËÇ°Ôø·´¶Ô¼×¹ÇÎÄÊÕ¹ºSun£¬µ«Õâһ¢¶ÏÉó²é»ú¹¹ÔÚ12ÔÂÓֳƣ¬¶Ô´Ë½»Ò×´ï³ÉÒ»¸öÂúÒâµÄ½á¹û±íʾÀÖ¹Û¡£Å·ÃËίԱ»á½«Ô ......