I believe everyone knows about the DB2 character set. So where is the importance of the DB2 character set for the DB2 database? The following uses MySql and DB2 as an example to explain the character set of the database.
The default character set is used when you create a database or a table,
SQL code in MySql
- CREATE TABLE fuck (
- id varchar(225) DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
- CREATE TABLE fuck (
- id varchar(225) DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
SQL code in DB2
- create database ktzpdbusing codeset UTF8 territory cn
- create database ktzpdb using codeset UTF8 territory cn
In this way, the character encoding of the database or each table is set to utf8. When we directly use the command window of mysql or db2 to insert Chinese characters, we cannot insert them, this is the code of the command window.
Generally, the character encoding in the Command window should be gbk, so that we can insert and display normally. For example, you can use the configuration file my. ini in Mysql to create a gbk or set names gbk in the window;
In DB2, set db2set DB2CODEPAGE = 1386 in the Command window. When we press Chinese to insert data into the table, the table data is actually stored in utf8, and in the Command window, we can see the Chinese normally due to the gbk setting.
When source d:/insertData. SQL or db2-tf d:/** in db2 :/**. when executing SQL commands such as SQL, the SQL statement must be consistent with the character encoding in the current command window, that is, the above gbk. You can save it as ANSI in notepad. If the SQL encoding is inconsistent, for example, utf8, the gbk on the client cannot identify the utf8 encoding format in the file. It cannot store Chinese or other non-English characters.
In short, if the built-in command window is used, the encoding of the MySql import file must be the same as the character encoding of the command window. Otherwise, the Chinese characters in the data cannot be recognized normally, the DB2 command window is usually set to 1386, that is, GBK. The file is also in ANSI format and will not go wrong!
DB2 update statements for records in the same table
Introduction to DB2 datetime Data Types
Six common DB2 command lines
Four precautions for DB2 Data Import
DB2 Management page size limit