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

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

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

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

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

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'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

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

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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
