The problem of creating a MySQL Chinese table is indeed a headache. The following is an example to illustrate the problem of creating a MySQL Chinese table. If you have encountered a problem of creating a MySQL Chinese table before, take a look.
Importing and exporting data in a database is the simplest and most necessary function.
For example, when the system is under development on a personal PC, the database has a lot of initialization data. After the system development is complete, you need to export the initialization data from the PC to an SQL script, you only need to import these SQL scripts on the server to complete database initialization.
However, the import of Chinese characters has become a big problem. When importing Chinese characters, the Data always reports an error "Data too long for column XX at row n"
This problem has always plagued me. Because the data volume was small in the past, I didn't need to import the function, so I had to re-initialize it again. I don't know how to initialize the data. It's too much data to reinitialize, but I always think there will be a way to solve this problem. Today I 've been searching for information online for more than half a day, and this problem is basically solved.
To clearly describe this problem, we will explain it in detail as follows:
1. Create a database
Microsoft Windows XP [version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C: \ Documents ents and Settings \ awish> mysql-u root-p
Enter password :*******
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 24 to server version: 5.0.27-community-nt
Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.
Mysql> create database test;
2. Set the data encoding to utf8.
- Mysql> use test;
- Database changed
- Mysql> set names utf8; // set the database character set to utf8
- Query OK, 0 rows affected (0.00 sec)
-
3. Create a data table
- Mysql> create table person
- -> (
- -> Id INT (8) not null AUTO_INCREMENT primary key,
- -> Name varchar (16) default 'nobody ',
- -> Birthday char (19 ),
- ->) ENGINE = InnoDB default charset = utf8 // create a data table and set the character set to utf8
- ->;
- Query OK, 0 rows affected (0.03 sec)
How to copy data from a MySQL table to a new table
Implementation of MySQL multi-Table Deletion
Advantages and disadvantages of MySQL independent tablespace
Restoration of MySQL MyISAM Table Structure
Two Methods for querying the number of table fields in MySQL