C#²Ù×÷MySQLÊý¾Ý¿âµÄ¼òµ¥Àý×Ó
×÷Õß: ÍõÕßÖ®½£(http://www.albertsong.com/) ÈÕÆÚ: 2008-01-05 22:10
×ÖÌå´óС: С ÖÐ ´ó
ʾÀýÑÝʾÁËÓÃC#²Ù×÷MySQLµÄ·½·¨£¬ÌṩÁËÈý¸ö¿ÉÖØÓõÄÀàMySqlDBUtil,MySqlPageUtil,Page¡£
±¾Ê¾ÀýÓÉ C#²Ù×÷AccessÊý¾Ý¿âµÄ¼òµ¥Àý×Ó£¨http://www.albertsong.com/read-56.html£©Ð޸ĶøÀ´¡£
1.Ê×ÏÈÏÂÔØMySQLÊý¾Ý¿âµÄ.NETÇý¶¯
http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-5.0.8.1-noinstall.zip/from/pick#mirrors
½«binĿ¼ÀïµÄMySql.Data.dllÎļþ¸´ÖƵ½¹¤³ÌĿ¼£¬²¢ÇÒ½«dllµÄÒýÓüÓÈëµ½ÏîÄ¿ÖУ¬ÕâÑù¾Í¿ÉÒÔͨ¹ýÏà¹ØµÄÀàÀ´²Ù×÷MySQLÊý¾Ý¿âÁË¡£
using MySql.Data.MySqlClient;
using System.Data;
Á¬½Ó×Ö·û´®£ºString connectionString = "server=127.0.0.1;user id=root; password=as; database=albertsong; pooling=false;charset=utf8";
Á¬½Ó×Ö·û´®Öи÷¸öÏîÄ¿µÄÒâ˼ÊǺÜÃ÷È·µÄ£¬ÐèҪעÒâµÄÊÇcharsetÓ¦¸ÃÉèÖóɺÍÊý¾Ý¿â±íµÄcharsetÒ»Ö£¬·ñÔò¿ÉÄܳöÏÖÖÐÎÄÂÒÂë¡£
È»ºó½«Õû¸öÏîÄ¿ÖеÄOleDbÓÃMySqlÌæ»»£¬ÕâÑù»ù±¾ÉϾͿÉÒÔÁË¡£²»Í¬µÄÊÇ´ø²ÎÊýµÄsqlÓï¾ä£¬
AccessÖÐÊÇ
string sql="insert into product(name,quantity,price,sale_date,checked_flag)values(?,?,?,?,?)";
parameters[0]=new MySqlParameter("@name",MySqlDbType.VarChar,100);
MySqlÖÐÓ¦¸ÄΪ
string sql="insert into product(name,quantity,price,sale_date,checked_flag)values(?name,?quantity,?price,?sale_date,?checked_flag)";
parameters[0]=new MySqlParameter("?name",MySqlDbType.VarChar,100);
2.È¡µÃMySQL×ÔÔö±êʶ×Ö¶ÎÔÚ²åÈëÊý¾ÝºóµÄidÖµ
cmd.CommandText = @"select @@identity";
int value = Int32.Parse(cmd.ExecuteScalar().ToString());
return value;
ÓÃcmd.CommandText = @"select LAST_INSERT_ID()";½á¹ûÒ»Ñù£¬Á½ÕßµÄÇø±ðûÓÐÑо¿¡£
3.·ÖÒ³²éѯ
ʹÓÃLimit×Ó¾äÀ´´¦Àí·ÖÒ³²éѯ£¬ÕâÑùÏà¶ÔÓÚAccessµÄ·ÖÒ³²éѯ£¬´úÂë´óÁ¿¼ò»¯£¬Ð§ÂÊÒ²»áÌá¸ß¡£
´úÂëÕâÀïÏÂÔØMySqlDBUtilDemo.rar (198.41 KB , ÏÂÔØ:2598´Î)
±¾Àý³ÌÊÇÒ»¸öc#µÄwinform³ÌÐò£¬µ«ÊÇÊý¾Ý·ÃÎÊÀà¿ÉÒÔÔÚWeb»·¾³ÏÂʹÓá£
ÔËÐÐÇ°ÏÈÀûÓÃbin\ReleaseϵÄsqlÓï¾äÎļþ½¨±í²¢ÐÞ¸ÄMySqlDBUtilÖеÄÁ¬½Ó×Ö·û´®¡£
±¾Àý³ÌÑÝʾÁË£º
1.MySQLÊý¾Ý¿âµÄ²åÈ룬¸üУ¬Ð޸ģ¬²éѯ£»
2.´ø²ÎÊýµÄsqlÓï¾äµÄʹÓ㬶ø²»ÊÇÆ´SQL£»
3.ʹÓÃLimit×Ó¾äµÄ·ÖÒ³²éѯ£»
Ïà¹ØÎĵµ£º
1¡¢°²×°Ä¿Â¼:
½«my.iniÖÐ:
datadirµÄÖµ¸ü¸ÄΪ£º"sql/data/"
basedirµÄÖµ¸ü¸ÄΪ£º"sql"
2¡¢½øÈësql/data/"£¬É¾³ýÎļþ¼ÐÍâµÄËùÓÐÎļþ¡£
net start mysql»Ø³µ……
×¢ÒâбÏß/
ÐÞ¸Äpswd
·½·¨1£ºmysqladmin -u root -p "old password" "new password" (´ËÃüÁîÎÞ·¨°ÑÃØÃÜÇå¿Õ)
·½·¨2£º ......
×î½üµÄÏîÄ¿ÖÐʹÓÃÁËMySQLÊý¾Ý¿â£¬Ò»Ð©MySQLµÄÐÂÓû§ÔÚÅäÖÃʹÓÃʱ»¹ÓÐЩ²»¹»ÊìÁ·£¬ÌØÔڴ˼Ǽ£¬·½±ã¿ª·¢ÍŶÓʹÓ㬸ÃÎÄÕÂËùÉæ¼°ÄÚÈݾù¿ÉÒÔÔÚMySQL²Î¿¼ÊÖ²áµÚ¶þÕ“°²×°MySQL”ÖÐÕÒµ½¡£MySQL°²×°ºó×Ô´øÁËÓ¢ÎIJο¼ÊֲᣬҲ¿ÉÒÔÔÚhttp://dev.mysql.com/doc/refman/5.1/zh/index.html²é¿´ÖÐÎÄ°æ±¾£ ......
±àÒëÁËÒ»¸öwindowsϵÄpython3Á¬½ÓMysqlµÄ¿â
mypysql
°æ±¾ÊÇ 0.5.1 £¬¸ù¾Ý¹Ù·½µÄÐÞ¸ÄÈÕÖ¾£¬Õâ¸ö°æ±¾ÐÞ¸ÄÁË0.5ÖÐÒ»¸öÄÚ´æй©ÎÊÌâ¡£
Ô´´úÂëºÍ±àÒëºóµÄÎļþΪ£º
http://211.147.215.55/down/mypysql-0.5.1-win.zip
mypysqlµÄ¹Ù·½µØÖ· https://sourceforge.net/projects/mypysql/
......
MysqlÂÒÂë²úÉúµÄÔÒò£º
²úÉú´ËÀàÎÊÌâµÄ×î¿ÉÄÜÊÇÄãµÄÊý¾Ý¿âÔÚ°²×°Ê±Ã»ÓÐÑ¡¶Ô×Ö·û¼¯£¬Õâ¸öÊ®·ÖÖØÒª.
Äã¿ÉÒÔͨ¹ýÈçϵķ½Ê½À´²é¿´£º´ò¿ªMysql´°¿Ú£¬ÔÚ´°¿ÚµÄ×î×óÉϽǵã»÷Êó±êÓÒ¼ü£¬Ñ¡ÔñÊôÐÔ£¬¾Í¿ÉÒÔ¿´µ½ÄãĬÈϵÄ×Ö·û±àÂëÁË£¨ÈçÏÂͼ£©£º
......
MysqlÔÚĬÈÏÇé¿öϽ¨Á¢±íµÄ×Ö·û±àÂëÊÇlatin1£¬ËùÒÔÔÚ²åÈëÖÐÎÄʱ»á³ö´í¡£
eg£º
1¡¢²é¿´±í½¨Á¢µÄsqlÔ´Â룺
1: sqlÃüÁshow create table users
2:
3: ½á¹û£º
4: CREATE TABLE `users` (
5: `userID` int(10) unsigned NOT NULL AUTO_INCREMENT,
6: `userName` varchar(4 ......