Home > Database > Mysql Tutorial > body text

How to batch modify the character set of mysql table

coldplay.xixi
Release: 2020-10-20 13:51:44
Original
3968 people have browsed it

How to batch modify the character set of mysql tables: first query all table names in the database; then splice the table names into the statements that modify the table character set; finally copy these statements and execute them.

How to batch modify the character set of mysql table

How to batch modify the character set of mysql table:

Change table encoding (character set):

ALTER TABLE TABLE_NAME DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
Copy after login

If there are many tables in a database that need to be modified, it will be very troublesome and time-consuming if there is no good way. There are many methods, the following one is relatively simple and easy to operate.

1. Query the statement of all table names in a database:

SELECT TABLE_NAME from information_schema.`TABLES` WHERE TABLE_SCHEMA = 'DATABASE_NAME';
Copy after login

2. To get all the table names, we can splice the table names into the statement above to modify the table character set, The following statement is obtained:

SELECT CONCAT('ALTER TABLE ',TABLE_NAME,' DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;') from information_schema.`TABLES` WHERE TABLE_SCHEMA = 'DATABASE_NAME';
Copy after login

After execution, what you get is the statement that modifies the character set of all tables in the database, and then just copy these statements and execute them.

I will use the demo database as an example to operate:

How to batch modify the character set of mysql table

How to batch modify the character set of mysql table

##More related free learning recommendations: mysql tutorial(Video)

The above is the detailed content of How to batch modify the character set of mysql table. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template