Creating a MySQL Database : MySQL « Database « Python Tutorial

Home
Python Tutorial
1.Introduction
2.Data Type
3.Statement
4.Operator
5.String
6.Tuple
7.List
8.Dictionary
9.Collections
10.Function
11.Class
12.File
13.Buildin Function
14.Buildin Module
15.Database
16.Regular Expressions
17.Thread
18.Tkinker
19.wxPython
20.XML
21.Network
22.CGI Web
23.Windows
Python Tutorial » Database » MySQL 
15.3.3.Creating a MySQL Database
import MySQLdb

myDB = MySQLdb.connect(host="127.0.0.1", port=3306)

cHandler = myDB.cursor()

cHandler.execute("CREATE DATABASE schedule")
cHandler.execute("USE schedule")

cHandler.execute("CREATE TABLE Arrivals (city TEXT,flight TEXT, time TEXT)")

cHandler.execute("SHOW TABLES")
results = cHandler.fetchall()
print results

cHandler.execute("DESCRIBE Arrivals")
results = cHandler.fetchall()
print results

myDB.close()
15.3.MySQL
15.3.1.Basic connection to MySQL with mysqldb
15.3.2.Connecting to a MySQL Database Server
15.3.3.Creating a MySQL Database
15.3.4.Adding Entries to a MySQL Database
15.3.5.Retrieving Entries from a MySQL Database
15.3.6.Create table, insert data, update data and select data
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.