The following articles mainly introduce the practical operation solutions that allow MySQL to support Chinese characters. MySQL to support Chinese characters is also favored to some extent as MySQL databases are generated, the following is a description of the specific content. I hope it will be helpful for your future study.
Abstract: The default Character Set of MySQL (the best combination with PHP) 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 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)
MySQL supports Chinese characters: Download MySQL (the best combination with PHP) 4.x. x
- Shell> gunzip <mysql()and php )))-version.tar.gz | tar-xvf-
- Shell> cd MySQL (best combination with PHP)-VERSION
- Shell> CFLAGS = "-O3-mcpu = pentium3 "\
- CXX = gcc \
- XXFLAGS = "-O3-mcpu = pentium3-felide-constructors "\
- ./Configure -- prefix =/app/MySQL (the best combination with PHP )\
- -- With -- charset = gbk \
- -- With-extra-charsets = "gbk gb2312 big5 utf8 "\
- -- With-unix-socket-path =/etc/MySQL (the best combination with PHP). sock \
- -- Enable-local-infile \
- -- Enable-thread-safe-client \
- -- Enable-Cycler \
- -- With-client-ldflags =-all-static \
- -- With-MySQL (the best combination with PHP) d-ldflags =-all-static
//-Mcpu optimizes compilation based on the CPU type, which can make your mysq performance better! There are many optional projects:
I386, ida-, 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 (best combination with PHP)
- Shell> bin/MySQL (the best combination with PHP) _ install_db -- user = root
- Shell> chown-R root.
- Shell> chown-R MySQL (the best combination with PHP) var
- Shell> chgrp-R MySQL (the best combination with PHP ).
- Shell>./bin/MySQL (the best combination with PHP) d_safe -- user = root -- default-character-set = gbk &
- Shell>./bin/MySQL (the best combination with PHP) admin-u root password 'new-password'
- Shell>./bin/MySQL (the best combination with PHP)-u root -- default-character-set = gbk-p
- MySQL (best combination with PHP)> 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 (best combination with PHP)> 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 (the best combination with PHP)> insert into cn values ("really? ", 1 );
MySQL supports Chinese characters. 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.
- Shell> bin/MySQL (best combination with PHP)-u root -- default-character-set = gbk-p
- MySQL (best combination with PHP)> use test
- MySQL (the best combination with PHP)> select * from cn;
- + -------- + ------ +
- | Zh | Chinese |
- + -------- + ------ +
- | Really? | 1 |
- + -------- + ------ +
- 1 row in set (0.00 sec)
Finally, modify the Startup file/etc/rc. d/rc. MySQL (the best combination with PHP) d.
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 describes how to enable MySQL to support Chinese characters. I hope it will help you in this regard.