for the code below i got error:
Traceback (most recent call last):
File "C:/Python26/testdb", line 6, in <module>
db = MySQLdb.connect ("host","testus er","test123"," TESTDB" )
File "C:\Python26\li b\site-packages\MySQLd b\__init__.py", line 81, in Connect
return Connection(*arg s, **kwargs)
File "C:\Python26\li b\site-packages\MySQLd b\connections.p y", line 170, in __init__
super(Connectio n, self).__init__( *args, **kwargs2)
OperationalErro r: (2005, "Unknown MySQL server host 'host' (11004)")
Traceback (most recent call last):
File "C:/Python26/testdb", line 6, in <module>
db = MySQLdb.connect ("host","testus er","test123"," TESTDB" )
File "C:\Python26\li b\site-packages\MySQLd b\__init__.py", line 81, in Connect
return Connection(*arg s, **kwargs)
File "C:\Python26\li b\site-packages\MySQLd b\connections.p y", line 170, in __init__
super(Connectio n, self).__init__( *args, **kwargs2)
OperationalErro r: (2005, "Unknown MySQL server host 'host' (11004)")
Code:
#!/usr/bin/python
import MySQLdb
# Open database connection
db = MySQLdb.connect("host","testuser","test123","TESTDB" )
# prepare a cursor object using cursor() method
cursor = db.cursor()
# Drop table if it already exist using execute() method.
cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
# Create table as per requirement
sql = """CREATE TABLE EMPLOYEE (
FIRST_NAME CHAR(20) NOT NULL,
LAST_NAME CHAR(20),
AGE INT,
SEX CHAR(1),
INCOME FLOAT )"""
cursor.execute(sql)
# disconnect from server
db.close()