search
HomeDatabaseMysql Tutorial解析MySQL完全中文化

解析MySQL完全中文化

Jun 07, 2016 pm 04:07 PM
mysqlChinese culturesystemBring your ownparse

由于系统自带的MySQL默认字符集不是gbk,因此给数据库的推广应用以及中文程序的开发带来极大的不便,在没完没了的GBK和UTF8的转换过程中消耗了我们无数的精力以及系统的资源。 先将slack支持中文,然后重新编译MySQL,原来系统MySQL的要先卸载: login:root

由于系统自带的MySQL默认字符集不是gbk,因此给数据库的推广应用以及中文程序的开发带来极大的不便,在没完没了的GBK和UTF8的转换过程中消耗了我们无数的精力以及系统的资源。

先将slack支持中文,然后重新编译MySQL,原来系统MySQL的要先卸载:

login:root<br>shell> removepkg mysql<br>shell> groupadd mysql<br>shell> cd /app<br>shell> mkdir mysql<br>shell> chmod 744 mysql<br>shell> useradd -G mysql -s <br>/bin/bash –p /app/mysql mysql<br>shell> chown -R mysql.mysql mysql

再下载MySQL4.x.x:

shell> gunzip | tar -xvf -<br>shell> cd mysql-VERSION<br>shell> CFLAGS="-O3 -mcpu=pentium3" \<br>CXX=gcc \<br>XXFLAGS="-O3 -mcpu=pentium3 <br>-felide-constructors" \<br>./configure --prefix=/app/mysql \<br>--with--charset=gbk \<br>--with-extra-charsets="gbk gb2312 <br>big5 utf8"\<br>--with-unix-socket-path=/etc/mysql.sock \<br>--enable-local-infile \<br>--enable-thread-safe-client \<br>--enable-assembler \<br>--with-client-ldflags=-all-static \<br>--with-mysqld-ldflags=-all-static

//-mcpu 根据CPU类型优化编译,可以让你的MySQL表现更好。可选项目很多:i386, i486, i586, i686, pentium, pentium-mmx, pentiumpro, pentium2, pentium3, pentium4, k6, k6-2, k6-3, athlon, athlon-tbird, athlon-4, athlon-xp,athlon-mp,winchip-c6, winchip2 , c3。执行:shell> make。错误时候执行:shell> make clean。

再回上一步:

<p>shell> make install<br>shell> cp support-files/my-medium.cnf /etc/my.cnf<br>shell> cd /app/mysql<br>shell> bin/mysql_install_db --user=root<br>shell> chown -R root .<br>shell> chown -R mysql var<br>shell> chgrp -R mysql .<br>shell> ./bin/mysqld_safe --user=root <br>--default-character-set=gbk &<br>shell> ./bin/mysqladmin -u root <br>password 'new-password'<br>shell> ./bin/mysql -u root <br>--default-character-set=gbk -p<br>mysql> status<br>...<br>Server characterset: gbk<br>Db characterset: gbk<br>Client characterset: gbk<br>Conn. characterset: gbk<br>....</p>

看见characterset全是gbk就成功了。

在UTF8字符集的老数据库中,创建中文支持表脚本如下,对字段加上字符集说明:

<p>CREATE TABLE `test`.`cn` (<br>`zh` CHAR(10) CHARACTER SET <br>gb2312 COLLATE gb2312_chinese_ci NOT NULL,<br>`中文` INT(11) NOT NULL<br>)<br>ENGINE = MYISAM;</p>

注:CHARACTER SET写GB2312和gbk都可以,gbk优于GB2312。

对于新创建的数据库加个默认字符集声明GBK,就不用建表时候每个字段声明了,这样看起来简单流畅,没有特殊的痕迹,建议多采用这种方法。

<p>mysql> CREATE DATABASE dbCN DEFAULT <br>CHARACTER SET gbk COLLATE gbk_chinese_ci;<br>CREATE TABLE `dbCN`.`cn` (<br>`zh` CHAR(10) NOT NULL,<br>`中文` INT(11) NOT NULL<br>)<br>ENGINE = MYISAM;<br>mysql> insert into cn values("真的?",1);</p>

注:如果这些脚本用bin/mysql命令行是输入不了,可以用mysql query Browser或者编程执行。

shell> bin/mysql -u root --default-character-set=gbk -p<br>mysql>use test<br>mysql> select * from cn;<br>+--------+------+<br>| zh | 中文 |<br>+--------+------+<br>| 真的?| 1 |<br>+--------+------+<br>1 row in set (0.00 sec)<br>-----------------------------

最后修改启动文件/etc/rc.d/rc.mysqld,改路径/app/mysql/bin/mysqld_safe,改路径/app/mysql/var/web.pid最后/app/mysql/bin/mysqld_safe 后面加入 --user=root --default-character-set=gbk。

【相关文章】

  • 提高MySQL查询效率的三个技巧
  • MySQL占有率不断增加 日下载超五万次
  • 无法远程登入MySQL数据库的几种解决办法

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment