How can I implement MySQL to support Chinese characters?

Source: Internet
Author: User

The following article describes how to implement MySQL to support Chinese characters. We all know that the default Character Set of the MySQL database that comes with the system is not gbk, therefore, it brings great inconvenience to the development of database promotion applications and Chinese programs.

The endless conversion process of GBK and UTF8 consumes countless energy and system resources. After exploring and trying to solve the problem of Chinese MySQL 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 best combination with PHP ), the original system MySQL (the best combination with PHP) should be uninstalled first.

Login: root

Shell> removepkg MySQL (the best combination with PHP)

Shell> groupadd MySQL (the best combination with PHP)

Shell> cd/app

Shell> mkdir MySQL (the best combination with PHP)

Shell> chmod 744 MySQL (best combination with PHP)

Shell> useradd-G MySQL (the best combination with PHP)-s/bin/bash-p/app/MySQL (the best combination with PHP) mySQL (best combination with PHP)

Shell> chown-R MySQL (the best combination with PHP). MySQL (the best combination with PHP)

Download MySQL (the best combination with PHP) 4.x. x

 
 
  1. Shell> gunzip <mysql()and php )))-version.tar.gz | tar-xvf-
  2. Shell> cd MySQL (best combination with PHP)-VERSION
  3. Shell> CFLAGS = "-O3-mcpu = pentium3 "\
  4. CXX = gcc \
  5. XXFLAGS = "-O3-mcpu = pentium3-felide-constructors "\
  6. ./Configure -- prefix =/app/MySQL (the best combination with PHP )\
  7. -- With -- charset = gbk \
  8. -- With-extra-charsets = "gbk gb2312 big5 utf8 "\
  9. -- With-unix-socket-path =/etc/MySQL (the best combination with PHP). sock \
  10. -- Enable-local-infile \
  11. -- Enable-thread-safe-client \
  12. -- Enable-Cycler \
  13. -- With-client-ldflags =-all-static \
  14. -- With-MySQL (the best combination with PHP) d-ldflags =-all-static

Mcpu optimizes compilation based on the CPU type, so that your mysq performance is better! Optional items many: i386, i386, i586, i686, pentium, pentium-mmx, pentiumpro, pentium2, pentium3, pentium4, k6, k6-2, k6-3,

 
 
  1. athlon, athlon-tbird, athlon-4, athlon-xp,athlon-mp,winchip-c6, winchip2 , c3.   
  2. shell> make  

Error

Shell> make clean

Back to the previous step

 
 
  1. Shell> make install
  2. Shells> cp support-files/my-medium.cnf/etc/my. cnf
  3. Shell> cd/app/MySQL (best combination with PHP)
  4. Shell> bin/MySQL (the best combination with PHP) _ install_db -- user = root
  5. Shell> chown-R root.
  6. Shell> chown-R MySQL (the best combination with PHP) var
  7. Shell> chgrp-R MySQL (the best combination with PHP ).
  8. Shell>./bin/MySQL (the best combination with PHP) d_safe -- user = root -- default-character-set = gbk &
  9. Shell>./bin/MySQL (the best combination with PHP) admin-u root password 'new-password'
  10. Shell>./bin/MySQL (the best combination with PHP)-u root -- default-character-set = gbk-p
  11. MySQL (best combination with PHP)> status
  12. ...
  13. Server characterset: gbk
  14. Db characterset: gbk
  15. Client characterset: gbk
  16. Conn. characterset: gbk
  17. ....

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 MySQL support table is as follows:

 
 
  1. Create table 'test'. 'cn '(
  2. 'Zh 'CHAR (10) character set gb2312 COLLATE gb2312_chinese_ci not null,
  3. 'Chinese' INT (11) NOT NULL
  4. )
  5. 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.

 
 
  1. MySQL (best combination with PHP)> create database dbCN default character set gbk COLLATE gbk_chinese_ci;
  2. Create table 'dbcn'. 'cn '(
  3. 'Zh 'CHAR (10) not null,
  4. 'Chinese' INT (11) NOT NULL
  5. )
  6. ENGINE = MYISAM;
  7. MySQL (the best combination with PHP)> insert into cn values ("really? ", 1 );

Note: if these scripts cannot be entered using the bin/MySQL Command Line (the best combination with PHP), you can use MySQL (the best combination with PHP) query Browser, or program execution.

 
 
  1. Shell> bin/MySQL (best combination with PHP)-u root -- default-character-set = gbk-p
  2. MySQL (best combination with PHP)> use test
  3. MySQL (the best combination with PHP)> select * from cn;
  4. + -------- + ------ +
  5. | Zh | Chinese |
  6. + -------- + ------ +
  7. | Really? | 1 |
  8. + -------- + ------ +
  9. 1 row in set (0.00 sec)
  10. ---------------------------------------------

Finally, modify the Startup file/etc/rc. d/rc. MySQL (the best combination with PHP)

Change path/app/MySQL (the best combination with PHP)/bin/MySQL (the best combination with PHP) d_safe

Change path/app/MySQL (the best combination with PHP)/var/web. pid

/App/MySQL (the best combination with PHP)/bin/MySQL (the best combination with PHP) add -- user = root -- default-character-set = gbk after d_safe

The above content is an introduction to MySQL's support for Chinese characters. I hope you will have some gains.

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.