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 character set by mysql

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

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to modify the mysql character set, 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 understand it!

Modify my.ini configuration file (mysql configuration file)

Character_set_server = utf8 # set character set

Restart the mysql database service

View the current database character set

Show VARIABLES like 'character%'

Second, modify the database character set

Alter database database name character set utf8

Ps: after modifying the database character set, you need to restart the mysql database.

Modify the character set of the table

ALTER TABLE table name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

Generate all table modification character set statements:

SELECT TABLE_NAME,CONCAT ('ALTER TABLE', TABLE_NAME,' DEFAULT CHARACTER SET', a. DEFAULTRACTERCHARACTERSETRACTERSETRACTERSETAMENE 'COLLATE', a.DEFAULTROCOLATIONANNAMEN') executeSQL FROM information_schema.SCHEMATA ainformationschema.TABLES bWHERE a.SCHEMA_NAME=b.TABLE_SCHEMAAND a.DEFAULTCOLATIONAND database name

IV. Modify the column character set

ALTER TABLE table name CHANGE column name VARCHAR (100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL

Generate all column modify character set statements:

Select b.tableroomnamereportb.columnaccounnamereportb.columnaccounnamereportb.collationationchangnamereparentific concat ('ALTER TABLE', b.tablefantnamereparentific 'MODIFY', b.columnlemnameparentific', b.DATARACTERTYPET'(', b.CHARACTERTERMAXIMUMCHARACTERCHARACTERTERMAXIMUMCHARACTERMAXIMUMLENGTHRENG')', CASE WHEN b.COLUMN_DEFAULT IS NULL THEN''ELSE CONCAT (' DEFAULT\'', b.COLUMNNDEFALT'\') END,' COMMENT\' ') executeSQL from information_schema.TABLES an instrument information schemas. Columns b where b.character_set_name IS NOT NULL and a.TABLE_SCHEMA=b.TABLE_SCHEMA AND a.TABLE_NAME=b.TABLE_NAMEAND a. TABLECOLATION schema schema' database name'is all the contents of how mysql modifies the character set. 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