The default MySQL character set provided by the system is not gbk. Therefore, it brings great inconvenience to the database promotion and application and the development of Chinese programs, the endless conversion between GBK and UTF8 consumes countless energy and system resources. First, slack will be enabled to support Chinese characters, and then MySQL will be re-compiled. The original MySQL system must first uninstall: login: rootshellremovepkgmy
The default MySQL character set provided by the system is not gbk. Therefore, it brings great inconvenience to the database promotion and application and the development of Chinese programs, the endless conversion between GBK and UTF8 consumes countless energy and system resources.
First, slack will be enabled to support Chinese characters, and then MySQL will be re-compiled. The original MySQL system must be uninstalled first:
login:rootshell> removepkg mysqlshell> groupadd mysqlshell> cd /appshell> mkdir mysqlshell> chmod 744 mysqlshell> useradd -G mysql -s /bin/bash –p /app/mysql mysqlshell> chown -R mysql.mysql mysql |
Download MySQL4.x. x again:
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -shell> cd mysql-VERSIONshell> CFLAGS="-O3 -mcpu=pentium3" \CXX=gcc \XXFLAGS="-O3 -mcpu=pentium3 -felide-constructors" \./configure --prefix=/app/mysql \--with--charset=gbk \--with-extra-charsets="gbk gb2312 big5 utf8"\--with-unix-socket-path=/etc/mysql.sock \--enable-local-infile \--enable-thread-safe-client \--enable-assembler \--with-client-ldflags=-all-static \--with-mysqld-ldflags=-all-static |
//-The mcpu can be compiled based on the CPU type to improve your MySQL Performance. Optional item lot: i386, i386, i586, i686, pentium, pentium-mmx, pentiumpro, pentium2, pentium3, pentium4, k6, K6-2, athlon, athlon-tbird, k6-3, athlon-xp, athlon-mp, winchip-c6, winchip2, c3. Run shell> make. Run shell> make clean in case of an error.
Back to the previous step:
shell> make installshell> cp support-files/my-medium.cnf /etc/my.cnfshell> cd /app/mysqlshell> bin/mysql_install_db --user=rootshell> chown -R root .shell> chown -R mysql varshell> chgrp -R mysql .shell> ./bin/mysqld_safe --user=root --default-character-set=gbk &shell> ./bin/mysqladmin -u root password 'new-password'shell> ./bin/mysql -u root --default-character-set=gbk -pmysql> status...Server characterset: gbkDb characterset: gbkClient characterset: gbkConn. characterset: gbk.... |
You can see that characterset is all gbk.
In the old database of the UTF8 character set, the script for creating a Chinese support table is as follows, and the character set description is added to the field:
Create table 'test'. 'cn' ('zh 'CHAR (10) character set gb2312 COLLATE gb2312_chinese_ci not null, 'China' INT (11) not null) ENGINE = MYISAM; |
Note: character set can write both GB2312 and gbk, and gbk is better than GB2312.
Add a default character set declaration GBK for the newly created database, so that you do not need to declare each field when creating the table. this method looks simple and smooth, with no special Traces. we recommend that you use this method more.
Mysql> create database dbCN default character set gbk COLLATE gbk_chinese_ci; create table 'dbcn '. 'cn' ('zh 'CHAR (10) not null, 'Chinese' INT (11) not null) ENGINE = MYISAM; mysql> insert into cn values ("true? ", 1 ); |
Note: If these scripts cannot be entered using the bin/mysql command line, you can use mysql query Browser or program execution.
Shell> bin/mysql-u root -- default-character-set = gbk-pmysql> use testmysql> select * from cn; + -------- + ------ + | zh | Chinese | + -------- + ------ + | true? | 1 | + -------- + ------ + 1 row in set (0.00 sec )----------------------------- |
Finally, modify the startup file/etc/rc. d/rc. mysqld, change path/app/mysql/bin/mysqld_safe, and change path/app/mysql/var/web. add -- user = root -- default-character-set = gbk after pid/app/mysql/bin/mysqld_safe.