Traceback (most recent call last):
File "C:/Python26/testdb", line 6, in <module>
db = MySQLdb.connect("host","testuser","test123","TESTD B" )
File "C:\Python26\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python26\lib\site-packages\MySQLdb\connections.py", line 170, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2005, "Unknown MySQL server host 'host' (11004)")
Expand|Select|Wrap|Line Numbers
- #!/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()