How to modify the character set by mysql
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!