Last active
January 18, 2017 11:46
-
-
Save tao4yu/8141934 to your computer and use it in GitHub Desktop.
在MySQL中建立中文表名及中文字段名
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# 在MySQL中建立中文表名及中文字段名 | |
# MySQLdb 默认编码为 latin-1,改为utf-8 | |
import MySQLdb as mdb | |
con = mdb.connect('localhost', 'root', 'root', 'testdb') | |
con.set_character_set('utf8') | |
with con: | |
cur = con.cursor() | |
cur.execute('set names utf8') | |
cur.execute('set character set utf8') | |
cur.execute('set character_set_connection=utf8') | |
cur.execute("create table 中文表名(Id int primary key auto_increment, 名称 text)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very good