Home  >  Article  >  Database  >  How to modify the character set in mysql?

How to modify the character set in mysql?

藏色散人
藏色散人Original
2019-05-18 15:19:4032916browse

Mysql method to modify the character set: first modify the "my.ini" configuration file; then modify the database character set through the "alter database database name character set utf8;" statement; and finally restart the mysql database service.

How to modify the character set in mysql?

1. Modify the my.ini configuration file (mysql configuration file)

character_set_server = utf8 #设置字符集

Restart the mysql database service

View the current Database character set

show VARIABLES like 'character%';

2. Modify the database character set

alter database 数据库名 character set utf8;

ps: After modifying the database character set, you need to restart the mysql database.

3. Modify the table character set

ALTER TABLE  表名 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.DEFAULT_CHARACTER_SET_NAME,' COLLATE ',a.DEFAULT_COLLATION_NAME,';') executeSQL FROM information_schema.SCHEMATA a,information_schema.TABLES bWHERE a.SCHEMA_NAME=b.TABLE_SCHEMAAND a.DEFAULT_COLLATION_NAME!=b.TABLE_COLLATIONAND b.TABLE_SCHEMA='数据库名'

4. Modify the column character set

ALTER TABLE  表名 CHANGE  列名  列名  VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;

Generate all columns Modify character set statement:

select b.table_name,b.column_name,b.character_set_name,b.collation_name
,CONCAT('ALTER TABLE ',b.table_name,' MODIFY ',b.column_name,' ',b.DATA_TYPE,'(',b.CHARACTER_MAXIMUM_LENGTH,') ',CASE WHEN b.COLUMN_DEFAULT IS NULL THEN ''  ELSE CONCAT('DEFAULT \'',b.COLUMN_DEFAULT,'\'') END,' COMMENT \'',b.COLUMN_COMMENT,'\';') executeSQL from information_schema.TABLES a,information_schema.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.TABLE_COLLATION!=b.COLLATION_NAMEand a.TABLE_SCHEMA='数据库名'

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

Statement:
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
Previous article:What language is mysql?Next article:What language is mysql?