Make MYSQL fully support Chinese _ MySQL

Source: Internet
Author: User
Tags mysql command line
Abstract: The default character set of mysql in 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. after exploring and trying to solve the problem of Chinese support, experience Abstract: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. after exploring and trying to solve the problem of Chinese support, I would like to share my experience with 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.
Bytes ----------------------------------------------------------------------------------------------------
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.
Bytes --------------------------------------------------------------------------------------------------------

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

Http://slack.linuxsir.org/main? Q = node/165

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.