Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÓÃpythonÁ¬½ÓmysqlÊý¾Ý¿â


#
-*- 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.executemany(sql, val)
except
Exception, e:
print
e
#
²éѯ³öÊý¾Ý
sql
=

"
select * from test1
"
cursor.execute(sql)
alldata
=
cursor.fetchall()
#
Èç¹ûÓÐÊý¾Ý·µ»Ø£¬¾ÍÑ­»·Êä³ö, alldataÊÇÓиö¶þάµÄÁбí
if
alldata:
for
rec
in
alldata:
print
rec[0], rec[
1
]
cursor.close()
conn.close()
0.ÒýÈëMySQLdb¿â
import MySQLdb
1.ºÍÊý¾Ý¿â½¨Á¢Á¬½Ó
conn=MySQLdb.connect(host="localhost",user="root",passwd="sa",db="mytable")
ÌṩµÄconnect·½·¨ÓÃÀ´ºÍÊý¾Ý¿â½¨Á¢Á¬½Ó,½ÓÊÕÊý¸ö²ÎÊý,·µ»ØÁ¬½Ó¶ÔÏó.
±È½Ï³£ÓõIJÎÊý°üÀ¨
host:Êý¾Ý¿âÖ÷»úÃû.ĬÈÏÊÇÓñ¾µØÖ÷»ú.
user:Êý¾Ý¿âµÇ½Ãû.ĬÈÏÊǵ±Ç°Óû§.
passwd:Êý¾Ý¿âµÇ½µÄÃØÃÜ.ĬÈÏΪ¿Õ.
db:Ò


Ïà¹ØÎĵµ£º

phpѧϰ±Ê¼Ç£¨12£©:PHP+MYSQLÁôÑ԰壨ÉÏ

require()  Óë  require_once()
    
      ͨ³£·ÅÔÚ PHP ³ÌÐòµÄ×îÇ°Ãæ£¬PHP ³ÌÐòÔÚÖ´ÐÐǰ£¬¾Í»áÏȶÁÈë require
ËùÖ¸¶¨ÒýÈëµÄÎļþ£¬Èç¹û³öÏÖ´íÎóÊÇÖÂÃüµÄ¡£
nclude()  Óë  include_once()
    
    &n ......

MYSQL ʼþµ÷¶ÈµÄÀý×Ó

1.SET GLOBAL event_scheduler = ON;
2.show processlist;
3.´´½¨Ò»¸ö±í test Ö÷Òª×Ö¶Î no,name,sex,age
4.¶Ô¸Ã±í²åÈ缸ÌõÊý¾Ý
5.´´½¨´æ´¢¹ý³Ìadd_age
drop procedure if exists add_age;
delimiter|
create procedure add_age()
begin
  start transaction;
  update eventtest set age = age +1;
&n ......

¹ØÓÚmysql µÄorder by rand()

 ¹Ù·½ÊÖ²áÉÏÊÇÕâôдµÄ£º
<!--
/* Font Definitions */
@font-face
{font-family:ËÎÌå;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{f ......

Python ÖÐÁгöĿ¼ÖÐËùÓÐÎļþµÄ·½·¨


Python´úÂë
import string, os, sys   
  
dir = '/var'  
print '----------- no sub dir'  
  
files = os.listdir(dir)   
for f in files:   
   ......

mysql alter Óï¾äÓ÷¨,Ìí¼Ó¡¢Ð޸ġ¢É¾³ý×ֶεÈ


//Ö÷¼ü
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;
//ÖØÃüÃûÁÐ
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ