MySQL database coding problems

Modify encoding format]

Modify the database encoding

ALTER database database_test character set utf8;

Modify the database table coding

ALTER table table_test character set utf8;

[External databases easily solve the garbage problem]

SET NAMES 'utf8';

It is equivalent to the following three instructions:

SET character_set_client = utf8;

SET character_set_results = utf8;

SET character_set_connection = utf8;

Create a database

mysql> create database name character set utf8;

Create a table

CREATE TABLE `type` (

`id` int(10) unsigned NOT NULL auto_increment,

`name` varchar(50) character set utf8 NOT NULL default '',

PRIMARY KEY (`id`)

) DEFAULT CHARSET=utf8;

Modify the database to utf8.

mysql> alter database name character set utf8;

Modify the default table with utf8.

mysql> alter table type character set utf8;

Modify the field with utf8

mysql> alter table type modify type_name varchar(50) CHARACTER SET utf8;

[Garbled] internal database

1. Modify the database configuration file (vi /etc/my.cnf)

- plus three lines at [mysqld] tab

default-character-set = utf8

character_set_server = utf8

lower_case_table_names = 1 // table names are case insensitive (this independent encoding)

- Add a line at [MySQL] tab

default-character-set = utf8

- Add a line at [the mysql.server] tab

default-character-set = utf8

- Add a line at [the mysqld_safe] tab

default-character-set = utf8

- Add a line at [client] tab

default-character-set = utf8

2. Restart the database service

3. Review the results set

show variables like "%char%";

show variables like "%collation%";

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159981.htm