diff options
| author | root <root@lalalizard.com> | 2012-12-18 12:26:34 -0500 |
|---|---|---|
| committer | root <root@lalalizard.com> | 2012-12-18 12:26:34 -0500 |
| commit | e6eef4f848d76a14fcd692de49d6e337acbf3384 (patch) | |
| tree | c9a567dea24f5135c3e0715c23ebd12b72a0a577 | |
| parent | 5e580cf29e38d69bb7931f8f85e0a45077df183f (diff) | |
Database utf8 fix tool
| -rw-r--r-- | tools/fix_utf8.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/fix_utf8.py b/tools/fix_utf8.py new file mode 100644 index 0000000..18cc206 --- /dev/null +++ b/tools/fix_utf8.py @@ -0,0 +1,21 @@ +#! /usr/bin/env python +import MySQLdb + +host = "localhost" +passwd = "h1NRFheXVS9crbm3" +user = "sj_main" +dbname = "sj_main" + +db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=dbname) +cursor = db.cursor() + +cursor.execute("ALTER DATABASE `%s` CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'" % dbname) + +sql = "SELECT DISTINCT(table_name) FROM information_schema.columns WHERE table_schema = '%s'" % dbname +cursor.execute(sql) + +results = cursor.fetchall() +for row in results: + sql = "ALTER TABLE `%s` convert to character set DEFAULT COLLATE DEFAULT" % (row[0]) + cursor.execute(sql) +db.close() |
