搜尋
首頁資料庫mysql教程解析MySQL完全中文化

解析MySQL完全中文化

Jun 07, 2016 pm 04:07 PM
mysql中文化系統自帶解析

由于系统自带的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数据库的几种解决办法

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
在MySQL中使用視圖的局限性是什麼?在MySQL中使用視圖的局限性是什麼?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)他們不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinsOrsubqueries.2)他們canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

確保您的MySQL數據庫:添加用戶並授予特權確保您的MySQL數據庫:添加用戶並授予特權May 14, 2025 am 12:09 AM

porthusermanagementinmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

哪些因素會影響我可以在MySQL中使用的觸發器數量?哪些因素會影響我可以在MySQL中使用的觸發器數量?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)複雜的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

mysql:存儲斑點安全嗎?mysql:存儲斑點安全嗎?May 14, 2025 am 12:07 AM

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

mySQL:通過PHP Web界面添加用戶mySQL:通過PHP Web界面添加用戶May 14, 2025 am 12:04 AM

通過PHP網頁界面添加MySQL用戶可以使用MySQLi擴展。步驟如下:1.連接MySQL數據庫,使用MySQLi擴展。 2.創建用戶,使用CREATEUSER語句,並使用PASSWORD()函數加密密碼。 3.防止SQL注入,使用mysqli_real_escape_string()函數處理用戶輸入。 4.為新用戶分配權限,使用GRANT語句。

mysql:blob和其他無-SQL存儲,有什麼區別?mysql:blob和其他無-SQL存儲,有什麼區別?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而ilenosqloptionslikemongodb,redis和calablesolutionsolutionsolutionsoluntionsoluntionsolundortionsolunsonstructureddata.blobobobissimplobisslowdeperformberbutslowderformandperformancewithlararengedata;

mySQL添加用戶:語法,選項和安全性最佳實踐mySQL添加用戶:語法,選項和安全性最佳實踐May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串數據類型常見錯誤?MySQL:如何避免字符串數據類型常見錯誤?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingSefectery.1)usecharforfixed lengengtrings,varchar forvariable-varchar forbariaible length,andtext/blobforlargerdataa.2 seterters seterters seterters

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)