Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql character set viewing and setting

Shulou Source: shulou.com Published: 2022-06-01 05:37:14 09月22日 Update

The character set problem of MySQL is mainly two concepts, one is Character Sets, the other is Collations, the former is character content and coding, and the latter is some rules for comparing the former. These two parameter sets can be specified at four levels: database instance, single database, table, column, and join.

one。 View MySQL database server

Mysql > show variables like'% char%'

Modify server character set

a. Temporary modification

Mysql > SET character_set_server=utf8

b. Permanent modification

Open / etc/mysql/my.cnf and add character-set-server=utf8 after [mysqld]

Note after modification: service mysql restart

two。 View database character set

Mysql > show variables like'% char%'

Modify database character set

a. Temporary change

Mysql > SET character_set_database=utf8

b. Permanent change

Just change the server level.

3. View the character set of the MySQL data Table (table)

Mysql > show table status from Database like'% countries%'

Modify table level

Mysql > ALTER TABLE table_name DEFAULT CHARSET utf8

four。 View the character set of the MySQL data column (column).

Mysql > show full columns from countries

Modify column

Mysql > ALTER TABLE tablename CHANGE colnum VARCHAR (20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL

Fifth, change the connection character set

a. Temporary change: mysql > SET character_set_client

b. Permanent change: open / etc/mysql/my.cnf and add default-character-set=utf8 after [client]

Note that restart after modification: service mysql restart

six。 View the character sets supported by the currently installed MySQL.

Mysql > show charset

Mysql > show char set

Permanent change:

Modify my.ini (under windows) or / etc/my.cnf (under linux) through configuration file

Add the following respectively

[mysqld]

Character_server_set=utf8

[mysql]

Default-character-set=utf8

[mysql.server]

Default-character-set=utf8

[mysql_safe]

Default-character-set=utf8

[client]

Default-character-set=utf8

Restart the service: service mysqld restart

Tags: Character character set data database permanent service server a. two content single parameter instance data table file concept level encoding rule question Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB OPPO Reno Linux Xiaomi