In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the method of batch modification of character set by mysql, which is very detailed and has certain reference value. Friends who are interested must finish it!
Mysql how to modify the character set in batches: first, you need to use statements to generate all the statements actually executed; then, based on the metadata table of MySQL, you can get a set of SQL lists that can be executed directly; finally, you can paste and execute the statements directly.
How to modify character sets in batches by mysql:
1. Modify database coding and character set
This step is relatively simple and can be performed directly:
ALTER DATABASE db_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin
two。 Modify the encoding and character set of data table and fields in the table
It takes two steps here.
First, you need to use statements to generate all the statements that are actually executed:
SELECT CONCAT ("ALTER TABLE `", TABLE_NAME, "`CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;") AS target_tablesFROM INFORMATION_SCHEMA.TABLESWHERE TABLE_SCHEMA= "db_name" AND TABLE_TYPE= "BASE TABLE"
Based on the metadata table of MySQL, this statement results in a list of SQL that can be executed directly, as follows:
ALTER TABLE `table1` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;ALTER TABLE `table2` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;ALTER TABLE `table3` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;ALTER TABLE `table4` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;ALTER TABLE `table5` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;ALTER TABLE `table6` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin
Where table1 to table6 are all the data tables in the database.
Then, paste and execute the statement directly.
Note that CONVERT TO is used instead of DEFAULT because the latter does not modify the encoding and character set of the fields in the table.
In addition, for databases with a large number of data tables, you can first export the results of the first step to a .sql file, and then execute it through the SQL file.
The above is all the contents of this article "how to modify the character set in batch by mysql". Thank you for reading! Hope to share the content to help you, more related 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.