Since the default MySQL character set of the system is not gbk, 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: root
Shell> removepkg mysql
Shell> groupadd mysql
Shell> cd/app
Shell> mkdir mysql
Shell> chmod 744 mysql
Shell> useradd-G mysql-s
/Bin/bash-p/app/mysql
Shell> chown-R mysql. mysql
Download MySQL4.x. x again:
Shell> gunzip <mysql-VERSION.tar.gz
| Tar-xvf-
Shell> cd mysql-VERSION
Shell> 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-cycler/
-- 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 install
Shells> cp support-files/my-medium.cnf/etc/my. cnf
Shell> cd/app/mysql
Shell> bin/mysql_install_db -- user = root
Shell> chown-R root.
Shell> chown-R mysql var
Shell> 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-p
Mysql> status
...
Server characterset: gbk
Db characterset: gbk
Client characterset: gbk
Conn. 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,
'Chinese' 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 ("Really? ", 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-p
Mysql> use test
Mysql> select * from cn;
+ -------- + ------ +
| Zh | Chinese |
+ -------- + ------ +
| Really? | 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
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service