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 to modify the table name by mysql

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Editor to share with you mysql how to modify the table name, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

If it means MyISAM, then you can go directly to the database directory mv.

Innodb does not work at all. If you have tested it yourself, you will be prompted that the relevant table does not exist.

The first method:

RENAME database olddbname TO newdbname

This is available in versions 5.1.7 to 5.1.23, but it is not officially recommended and there is a risk of data loss.

The second method:

1. Create a database that needs to be changed to a new name.

2.mysqldum exports the database to be renamed

3. Delete the original old library (determine if it is really needed)

Of course, this method is safe, but if the amount of data is large, it will be time-consuming. Alas, I didn't even think of this method at that time, and I really wanted to die.

The third method:

I'm going to use a script here. It's very simple. I'm sure everyone can understand it.

#! / bin/bash

# suppose you change the name of the sakila database to new_sakila

# MyISAM can directly change the files in the database directory

Mysql-uroot-p123456-e'create database if not exists new_sakila'

List_table=$ (mysql-uroot-p123456-Nse "select table_name from information_schema.TABLES where TABLE_SCHEMA='sakila'")

For table in $list_table

Do

Mysql-uroot-p123456-e "rename table sakila.$table to new_sakila.$table"

Done

Rename table, the command to change the table name, is used here, but if the new table name is followed by a database name, the table from the old database will be moved to the new database, so this method is safe and fast.

The above is all the contents of the article "how to change the table name in mysql". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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: 0

*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