First Kind
First, modify the My.ini configuration file (MySQL configuration file)
Character_set_server = UTF8 #设置字符集
Restart MySQL database service
View the current database character set
Show VARIABLES like ' character% ';
Second, modify the database character set
ALTER DATABASE name character set UTF8;
PS: After modifying the database character set, the MySQL database needs to be restarted.
Third, modify the table character set
ALTER table name DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci
Iv. modifying the column character set
ALTER table table name change column name VARCHAR (+) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT null;
The second Kind
One is to modify the table's encoding format.
[SQL]View Plain Copy
- ALTER table 'table ' DEFAULT CHARACTER SET UTF8;
Modify the encoding format of a field because the table's encoding is changed to a field, so also modify the field modify field only one
[SQL]View Plain Copy
- ALTER TABLE ' tablename ' Change ' field name 1 ' Field Name 2 ' VARCHAR ( CHARACTER) SET UTF8 not NULL;
The ultimate way to modify multiple lines
[SQL]View Plain Copy
- Alter table ' tablename ' convert to character set UTF8;
Third Kind
1: View the current character encoding method mysql> show variables like '%character% '; +--------------------------+----------------------------+ | variable_name | Value |+--------------------------+----------------------------+|character_set_client |latin1 || Character_set_connection |latin1 | | Character_set_database |latin1 | | Character_set_filesystem |binary | | Character_set_results |latin1 | | Character_set_server |latin1 | | Character_set_system |utf8 | | Character_sets_dir | /usr/share/mysql/charsets/|+--------------------------+----------------------------+8 rows in Set (0.00 sec) When the character encoding is latin1, the user inserts a character type (char) record into the data table, which may not display the character type's data properly when displaying this record, so we modify the MySQL character encoding to UTF8. The operation is as follows: Step 2: Modify the MY.CNF configuration file as follows (/ETC/MY.CNF): [client] #password = Your_passwordport = 3306socket =/var/ Lib/mysql/mysql.sockdefault-character-set=utf8 #设置默认Encoded as UTF8
Modify the MySQL database character set to UTF8