Created
July 6, 2017 13:45
-
-
Save afit/5ac55e7d70f932e18573237953103fae to your computer and use it in GitHub Desktop.
Convert all MySQL tables to UTF-8 w/ general CI
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 | |
import warnings | |
warnings.simplefilter("ignore", DeprecationWarning) | |
warnings.filterwarnings("ignore", ".*Module _mysql was already imported.*") | |
warnings.filterwarnings("ignore", ".*Module timezones was already imported.*") | |
import os, sys | |
sys.stdout = sys.stderr | |
project = os.path.dirname( __file__ ) | |
workspace = os.path.dirname( project ) | |
sys.path.append( '%s/project/' % project ) | |
sys.path.append( '%s/apps/' % project ) | |
sys.path.append( '%s/../awdit-libs/' % project ) | |
from project import settings | |
from django.core.management import setup_environ | |
setup_environ(settings) | |
from django.db import connection | |
cursor = connection.cursor() | |
cursor.execute('SHOW TABLES') | |
results=[] | |
for row in cursor.fetchall(): results.append(row) | |
for row in results: cursor.execute('ALTER TABLE %s CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' % (row[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment