I. mysql multi-character set support
1. Set the mysqld service to support multiple character sets at the same time
Change the default Character Set of the mysqld service to utf8 and support the latin1, gbk, gb2312, big5, and ascii character sets. Different character sets can be used for different databases and tables.
Step 1: add the character set support option in the./configure step, for example:
Shell>./configure -- with-charset = utf8 -- with-collation = utf8_bin -- with-extra-charsets = big5, ascii, gb2312, gbk, utf8, latin1
// The default Character Set defaults to latin1.
// The available collation values of utf8 are utf8_bin, utf8_general_ci, and utf8_unicode_ci.
// Extra supports "-- with-extra-charsets = all ".
Step 2: Modify config. the h header file searches for the rows defining character set variables such as utf8, gbk, and gb2312, and confirms the following content (if not, manually add it). For example:
# Define HAVE_CHARSET_ascii 1
# Define HAVE_CHARSET_big5 1
# Define HAVE_CHARSET_gb2312 1
# Define HAVE_CHARSET_gbk 1
# Define HAVE_CHARSET_latin1 1
# Define HAVE_CHARSET_utf8 1
// It took a lot of effort to modify config. h at the beginning. "mysql>" the Error "Error 1115" is always reported when non-default character sets are used in the environment:
Mysqld> set names gbk;
ERROR 1115 (42000): Unknown character set: 'gbk'
// After it is sent to the./configure file, variable definitions such as gbk and gb2312 are not automatically enabled in the config. h file and have to be manually modified and added.
2. Verify that mysqld supports multiple character sets.
1) view the character sets supported by the current mysql database
Mysql> show character set;
2) view the checking rules available for the corresponding Character Set
Mysql> show collation like 'gb % ';
Mysql> show collation like 'utf8% ';
3) view the default Character Set status of the current mysql Server
Mysql> status
......
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
4) Specify the default character set used when creating a database:
Mysql> create database testdb default character set utf8;
Mysql> show create database testdb; // verify the database creation Information
5) Specify the default character set used when creating a data table:
Mysql> create table testdb. tb1 (id int (10) unsigned not null AUTO_INCREMENT, name varchar (15) not null default '', primary key (id) ENGINE = MyISAM default character set gb2312;
Mysql> show create table testdb. tb1; // verify the data table creation information.
6) set the default character set in mysql> client environment
Mysql> set NAMES utf8;