Sunday, February 26, 2012

mysqlの備忘録(2)

参考: http://2php.jp/mysql/insert.html


  • データベースを選択
use

  •  テーブルを作成
create table ( , [, ...]);

  • テーブルのフィールドを参照
show fields from ;
or
describe ;


  • 挿入
insert into values(, [, ...]);


  • MySQL-pythonのインストール
sudo easy_install MySQL-python

  • pythonからの参照

import MySQLdb
db = MySQLdb.connect(host="localhost", user="joe", passwd="secret", db="db56a")
cursor = db.cursor()
cursor.execute("SELECT * FROM animals")
result = cursor.fetchall()
for record in result:
print record[0] , "-->", record[1]

No comments:

Post a Comment