Allow MYSQL to fully support Chinese Characters

Source: Internet
Author: User

Built-inMysqlThe default character set is not gbk, which makes it inconvenient for database promotion and application and Chinese program development, the endless conversion between GBK and UTF8 consumes countless energy and system resources. after exploring and trying to solve the problem of Chinese support, I would like to share my experience with you and hope to help you.

First, let slack support Chinese characters. You can refer to the "linuxsir.org Slackware discussion area" and re-compile mysql. The original mysql system should 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

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

//-Mcpu optimizes compilation based on the CPU type, which can make your mysq performance better! 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.

Shell> make

------------------------------------------

Error

Shell> make clean

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

....

If you see that characterset is full of gbk, it will be successful.

--------------------------------------------

In the old database of the UTF8 character set, the script for creating a Chinese support table is as follows:

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

Change path/app/mysql/var/web. pid

/App/mysql/bin/mysqld_safe followed by -- user = root -- default-character-set = gbk

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.