Skip to content

Instantly share code, notes, and snippets.

@tao4yu
Last active January 18, 2017 11:46
Show Gist options
  • Save tao4yu/8141934 to your computer and use it in GitHub Desktop.
Save tao4yu/8141934 to your computer and use it in GitHub Desktop.
在MySQL中建立中文表名及中文字段名
# ! /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)")
@xiaodongzi
Copy link

very good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment