Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does MySQL batch convert table names to lowercase

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 264

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report