pythonÄ£¿éÖ®MySQLdb: ÓÃpythonÁ¬½ÓmysqlÊý¾Ý¿â
mysqlÊÇÒ»¸öÓÅÐãµÄ¿ªÔ´Êý¾Ý¿â£¬ËüÏÖÔÚµÄÓ¦Ó÷dz£µÄ¹ã·º£¬Òò´ËºÜÓбØÒª¼òµ¥µÄ½éÉÜÒ»ÏÂÓÃpython²Ù×÷mysqlÊý¾Ý¿âµÄ·½·¨¡£python²Ù×÷Êý¾Ý¿âÐèÒª°²×°Ò»¸öµÚÈý·½µÄÄ£¿é£¬ÔÚhttp://mysql-python.sourceforge.net/
ÓÐÏÂÔغÍÎĵµ¡£
ÓÉÓÚpythonµÄÊý¾Ý¿âÄ£¿éÓÐרÃŵÄÊý¾Ý¿âÄ£¿éµÄ¹æ·¶£¬ËùÒÔ£¬Æäʵ²»¹ÜʹÓÃÄÄÖÖÊý¾Ý¿âµÄ·½·¨¶¼´óͬСÒìµÄ£¬ÕâÀï¾Í¸ø³öÒ»¶Îʾ·¶µÄ´úÂ룺
#
-*- encoding: gb2312 -*-
import
os, sys, string
import
MySQLdb
#
Á¬½ÓÊý¾Ý¿â¡¡
try
:
conn
=
MySQLdb.connect(host
=
'
localhost
'
,user
=
'
root
'
,passwd
=
'
xxxx
'
,db
=
'
test1
'
)
except
Exception, e:
print
e
sys.exit()
#
»ñÈ¡cursor¶ÔÏóÀ´½øÐвÙ×÷
cursor
=
conn.cursor()
#
´´½¨±í
sql
=
"
create table if not exists test1(name varchar(128) primary key, age int(4))
"
cursor.execute(sql)
#
²åÈëÊý¾Ý
sql
=
"
insert into test1(name, age) values ('%s', %d)
"
%
(
"
zhaowei
"
,
23
)
try
:
cursor.execute(sql)
except
Exception, e:
print
e
sql
=
"
insert into test1(name, age) values ('%s', %d)
"
%
(
"
ÕÅÈý
"
,
21
)
try
:
cursor.execute(sql)
except
Exception, e:
print
e
#
²åÈë¶àÌõ
sql
=
"
insert into test1(name, age) values (%s, %s)
"
val
=
((
"
ÀîËÄ
"
,
24
), (
"
ÍõÎå
"
,
25
), (
"
ºéÁù
"
,
26
))
try
:
cursor.ex
Ïà¹ØÎĵµ£º
ÔÎÄ
PythonºÍC·Ö±ðÓÐן÷×ÔµÄÓÅȱµã£¬ÓÃPython¿ª·¢³ÌÐòËٶȿ죬¿É¿¿ÐԸߣ¬²¢ÇÒÓÐÐí¶àÏÖ³ÉÄ£¿é¿É¹©Ê¹Ó㬵«Ö´ÐÐËÙ¶ÈÏà¶Ô½ÏÂý£»CÓïÑÔÔòÕýºÃÏà·´£¬ÆäÖ´ÐÐËٶȿ죬µ«¿ª·¢Ð§Âʵ͡£ÎªÁ˳ä·ÖÀûÓÃÁ½ÖÖÓïÑÔ¸÷×ÔµÄÓŵ㣬±È½ÏºÃµÄ×ö·¨ÊÇÓÃPython¿ª·¢Õû¸öÈí¼þ¿ò¼Ü£¬¶øÓÃCÓïÑÔʵÏÖÆä¹Ø¼üÄ£¿é¡£±¾ÎĽéÉÜÈçºÎÀûÓÃCÓïÑÔÀ´À©Õ¹PythonµÄ¹¦ ......
MySQL
ÊÇÒ»¸ö·Ç³£Á÷ÐеÄСÐ͹ØϵÐÍÊý¾Ý¿â¹ÜÀíϵͳ£¬2008Äê1ÔÂ16ºÅ±»Sun¹«Ë¾ÊÕ¹º¡£Ä¿Ç°MySQL±»¹ã·ºµØÓ¦ÓÃÔÚInternetÉϵÄÖÐСÐÍÍøÕ¾ÖС£ÓÉ
ÓÚÆäÌå»ýС¡¢Ëٶȿ졢×ÜÌåÓµÓгɱ¾µÍ£¬ÓÈÆäÊÇ¿ª·ÅÔ´ÂëÕâÒ»Ìص㣬Ðí¶àÖÐСÐÍÍøվΪÁ˽µµÍÍøÕ¾×ÜÌåÓµÓгɱ¾¶øÑ¡ÔñÁËMySQL×÷ΪÍøÕ¾Êý¾Ý¿â¡£
1¡¢phpMyAdmin£¨http://www.phpmyadmin.ne ......
1¡¢Ð½¨Êý¾ÝÔ´Îļþmysql-ds.xml,ÎļþÄÚÈÝÈçÏ£º
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>MySqlDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/mydatabase?useUnico ......
MYSQL--my.cnfÅäÖÃÖÐÎÄÏê½â ZZ2007Äê08ÔÂ16ÈÕ ÐÇÆÚËÄ 15:53mysqld³ÌÐò--Ŀ¼ºÍÎļþ
ÒýÓÃ
basedir = path ʹÓøø¶¨Ä¿Â¼×÷Ϊ¸ùĿ¼(°²×°Ä¿Â¼)¡£
character-sets-dir = path ¸ø³ö´æ·Å×Å×Ö·û¼¯µÄĿ¼¡£
datadir = path ´Ó¸ø¶¨Ä¿Â¼¶ÁÈ¡Êý¾Ý¿âÎļþ¡£
pid-file = filename Î ......
Èç¹ûÄãËÑË÷GOOGLE£¬Äã»áÕÒµ½ºÜ¶à¹ØÓÚmysqlµÄËæ»úÊý£¬ËûÃÇ»áÕâÑù˵
Éú³É£³£¬£¶Ö®¼äµÄËæ»úÕûÊý
FLOOR(3 + (RAND() * 6))
ÔÚ4ºóÃæÌí¼ÓÒ»¸ö3µ½6Ö®¼äµÄÕûÊý
CONCAT(343,FLOOR(3 + (RAND() * 6)))
ÔÚijһ×ֶκóÃæÌí¼Óһλ£³£¬£¶Ö®¼äµÄÕûÊý
UPDATE test SET xx= CONCAT(xx,FLOOR(3 +(RAND() * 6)));
µ«ÊÇÎÒ˽×Ô²âÊÔÁËһϣ¬ ......