Recommendation: connecting your MySQL database to Chinese completely _ MySQL

Source: Internet
Author: User
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, we will allow slack to support Chinese characters. you can refer to linuxsir. o

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, slack will support Chinese characters. you can refer to "Slackware discussion area of linuxsir.org" and re-compile MySQL. The original MySQL system should 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:

     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-validator \ -- with-client-ldflags =-All-static \ -- with-mysqld-ldflags =-all-static //-mcpu optimized compilation based on the CPU type, which can make your MySQL 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, c3shell> make ---------------------------------------- shell> make clean 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 ....

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, 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.

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.