# coding:UTF-8
import MySQLdb
conn = MySQLdb.Connect(
host = '127.0.0.1',
port = 3306,
user = 'root',
passwd = 'root',
db = 'python',
charset = 'utf-8'
)
cursor = conn.cursor()
print conn
print cursor
cursor.close()
conn.close()
Traceback (most recent call last):
File "C:\Users\yezi\workspace\TestPython\my_Mysqldb\test_connection.py", line 10, in <module>
charset = 'utf-8'
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 215, in __init__
self.set_character_set(charset)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 298, in set_character_set
super(Connection, self).set_character_set(charset)
_mysql_exceptions.OperationalError: (2019, "Can't initialize character set utf-8 (path: C:\\mysql\\\\share\\charsets\\)")