Get the App
SLTechnology News&Howtos  ›  Database  › 

How does MySQL batch convert table names to lowercase

Shulou Source: shulou.com Published: 2022-05-31 19:10:14 10月24日 Update

This article introduces the knowledge of "how to convert table names to lowercase in batches by MySQL". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

#! / usr/bin/env python

#-*-encoding:utf8-*-

#

Import MySQLdb

Import time

Step = 0

Db = MySQLdb.connect (host = '192.168.20.42) 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.% swatches'% (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 ()

This is the end of the introduction of "how to batch convert the table name to lowercase by MySQL". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Lowercase content more knowledge practical successful learning next dilemma reality situation article case editing website industry process high quality learning related output Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Linux Shulou Information NVidia Shulou Tech Info