MySQL批量转换表名为小写(Python脚本)
-
feelpurple
2018-03-23 11:27:26
-
MySQL
-
原创
-
#!/usr/bin/env python
-
# -*-encoding:utf8-*-
-
#
-
-
import MySQLdb
-
import time
-
step = 0
-
db = MySQLdb.connect(host = '192.168.20.42',port = 61306,user = 'test',passwd = 'test' , db = 'information_schema')
-
conn = db.cursor()
-
-
sql = '''select TABLE_SCHEMA, table_name from information_schema.tables where table_schema not in ('information_schema', 'performance_schema', 'mysql') '''
-
# print sql
-
conn.execute(sql)
-
if conn.rowcount > 0:
-
for item in conn.fetchall():
-
sql = '''rename table %s.%s to %s.%s''' % (item[0], item[1], item[0], item[1].lower())
-
if item[1].isupper():
-
print sql
-
conn.execute(sql)
-
-
time.sleep(0.5)
-
-
conn.close()
-
db.close()